Monday, May 25, 2020

#1 2020-05-19 08:45:17 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 4344

How to, get the id of an account in Mail?

Hello.

I assumed that it was a simple task but I found no clean way to get the id of the account owning a given mailbox.
Here is what I got for a mailbox named "fournisseurs" (fournisseurs.mbox) available on my machine.

Applescript:

set boxName to "fournisseurs"
tell application "Mail"
   set boxProperties to properties of mailbox boxName --> {account:missing value, name:"fournisseurs", container:account id "30ACBF46-881C-40AC-B33B-500D53832270", class:container, unread count:0}
   set boxContainer to (get container of boxProperties) --> account id "30ACBF46-881C-40AC-B33B-500D53832270"
   try
       set boxID to id of boxContainer -- I assumed that it would return the id
   on error errMsg -- but it doesn't
       log errMsg (*Erreur dans Mail : Il est impossible d’obtenir account id "30ACBF46-881C-40AC-B33B-500D53832270".*)
       set boxID to item 2 of my decoupe(errMsg, quote)
   end try
end tell
return boxID --> "30ACBF46-881C-40AC-B33B-500D53832270"

#=====

on decoupe(t, d)
   local oTIDs, l
   set {oTIDs, AppleScript's text item delimiters} to {AppleScript's text item delimiters, d}
   set l to text items of t
   set AppleScript's text item delimiters to oTIDs
   return l
end decoupe

#=====

I deliberately split the task in single ones.
Is it a way to get the id without relying upon an error message ?

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) mardi 19 mai 2020 16:45:10

Online

 

#2 2020-05-19 01:09:27 pm

KniazidisR
Member
Registered: 2019-03-03
Posts: 1258

Re: How to, get the id of an account in Mail?

Yvan Koenig wrote:

Hello.
I assumed that it was a simple task but I found no clean way to get the id of the account owning a given mailbox.


It is because to get full access to all properties of mailbox you should tell to account object instead of Mail.app.

Applescript:


tell application "Mail" to set theIDs to id of accounts of mailboxes of accounts

Here, the 1st account is property of certain mailbox, and 2nd account is property of Mail.app

Applescript:


tell application "Mail" to id of account of mailbox "Notes" of account "KNIAZIDIS.ROMPERT@gmail.com"
--> "30ACBF46-881C-40AC-B33B-500D53832270"

Last edited by KniazidisR (2020-05-19 01:26:37 pm)


Model: MacBook Pro
OS X: Catalina 10.15.4
Web Browser: Safari 13.1
Ram: 4 GB

Offline

 

#3 2020-05-19 02:34:53 pm

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 4344

Re: How to, get the id of an account in Mail?

Thanks to try but you are wrong.

Applescript:

use AppleScript version "2.4"
use framework "Foundation"
use scripting additions
on combineSublistsIn:theList
   set theArray to current application's NSArray's arrayWithArray:theList
   set unionOfArrays to (theArray's valueForKeyPath:"@unionOfArrays.self") as list
   return unionOfArrays
end combineSublistsIn:


tell application "Mail"
   set theIDs to id of accounts of mailboxes of accounts
   set theNames to name of mailbox of accounts --> {{"Important", "Suivis", "Tous les messages", "Brouillons", "Messages envoyés", "Corbeille", "Spam", "Deleted Messages", "oubliés", "Personnel", "Professionnel", "Reçus", "Sent Messages", "Notes", "INBOX"}, {"Deleted Messages", "Drafts", "INBOX", "Junk", "Sent Messages"}, {}, {}, {}, {}, {"INBOX", "DRAFT", "OUTBOX", "TRASH", "QUARANTAINE"}, {"forums Apple", "SentFolder:Sent Messages", "Trash", "trashFolder:Deleted Messages", "z-attente", "Archive", "- Import", "Notes", "INBOX", "Drafts", "Sent Messages", "Deleted Messages", "Junk"}}
   set allNames to name of every mailbox --> {" laPoste…", "aaab", "gag amazon", "aaa", "aab", "batiactu", "maison à part", "Batiactu…", "documents Box", "uninstall", "Box", "vieilleries SFR", "changement d'opérateur", "BBBBBBBBB Gérard &+", "CCCCCCCC Monique", "DDDDDDDD J.P.", "INSA MMMMMMM", "KKKKKKKK Richard", "MMMMMMM Daniel", "MOMOM Frédéric", "PPPPPPP François", "Walter HHHHHHHH", "Copains", "Crédit Agricole", "accident", "facéties", "transactions", "ebay", "AAAAA Alain", "SSSSSSSSS", "famille MMMMMM+", "Famille_SSSSS+", "Famille_WWWWWW+", "Famille_WWWWWWW+", "inondations", "Succession", "Succession papa", "Famille", "forum AppleScript shell", "forum AppleScript FR", "2004", "AscriptUS 2005_01", "AscriptUS 2005_02", "AscriptUS 2005_03", "AscriptUS 2005_04", "AscriptUS 2005_05", "AscriptUS 2005_06", "AscriptUS 2005_07", "AscriptUS 2005_08", "AscriptUS 2005_09", "AscriptUS 2005_10", "AscriptUS 2005_11", "AscriptUS 2005_12", "2005", "AscriptUS 2006_01", "AscriptUS 2006_02", "AscriptUS 2006_04", "AscriptUS 2006_05", "AscriptUS 2006_06", "AscriptUS 2006_07", "AscriptUS 2006_10", "AscriptUS 2006_11", "AscriptUS 2006_12", "2006", "AscriptUS 2007_01", "AscriptUS 2007_02", "AscriptUS 2007_03", "AscriptUS 2007_04", "AscriptUS 2007_05", "AscriptUS 2007_06", "AscriptUS 2007_07", "AscriptUS 2007_08", "AscriptUS 2007_09", "AscriptUS 2007_10", "AscriptUS 2007_11", "AscriptUS 2007_12", "2007", "AscriptUS 2008_01", "AscriptUS 2008_02", "AscriptUS 2008_03", "AscriptUS 2008_04", "AscriptUS 2008_05", "AscriptUS 2008_06", "AscriptUS 2008_07", "AscriptUS 2008_08", "AscriptUS 2008_09", "AscriptUS 2008_10", "AscriptUS 2008_11", "AscriptUS 2008_12", "2008", "2009", "2010", "2011", "2012", "2013", "2014", "2015", "2016", "2017", "forum AppleScript US", "forum inDesign", "Amazon", "Apple_Care", "AppleStore", "euro-Apple", "iTunes Store", "Apple", "aVosMac", "CreaMagic", "Divers", "free", "Adobe", "Alsoft_DiskWarrior", "Carbon Copy Cloner", "FileMaker", "MozoDojo", "Onyx", "Pangea", "SmithMicro (Internet Cleanup)", "tidy_up", "TRI-EDRE", "logiciels achetés", "MAAF", "MyFonts", "Nikon", "PHP", "Ronchamp", "fournisseurs", "iCloud bizarres", "Late Night", "m4e", "Mosaic-Tumblr", "4seed", "Seedx", "archives Yahoo", "SSSSS SSSSSS", "Arnaud", "Gilles", "Slice42", "Claude BBBBBBB", "Support", "traités", "zzzz", "Outbox", "Sent Messages", "Deleted Messages", "Junk"}
end tell
set theIDsUnion to my combineSublistsIn:theIDs
set theNamesUnion to my combineSublistsIn:theNames

{count theIDsUnion, count theNamesUnion, count allNames}
--> {38, 38, 147, true}

Of course, some names are anonymized.
Your proposal just miss a lot of names and worse, some names returned by your scheme are unavailable in the supposed “list of all mailboxes”.
Important, Suivis, Brouillons, Tous les messages, Brouillons, Messages envoyés, Corbeille, Spam, oubliés, Personnel, Professionnel, Reçus,

Notes and Junk are available twice in your list, only once in the other one.
Deleted Messages and Sent Messages are available 4 times in your list, only once in the other one.
INBOX is available 4 times in your list, miss in the other list.
DRAFT, TRASH, Trash, trashFolder, QUARANTAINE, forums Apple, z-attente, Archive, - Import which are available once in your list, miss in the other list.
Drafts which is available twice in your list, miss in the other list.

OUTBOX which is available once in your list, is spelled Outbox in the other list.

I really see no logic in this behavior (which of course is not your fault).

Happily, my awful trick give me the id of every mailbox but it's not satisfying.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) mardi 19 mai 2020 21:59:55

Online

 

#4 2020-05-19 02:58:09 pm

KniazidisR
Member
Registered: 2019-03-03
Posts: 1258

Re: How to, get the id of an account in Mail?

Yvan Koenig wrote:

I really see no logic in this behavior


I do not see any strangeness in this behavior. It is logical that mailboxes (at least standard ones) have only one original owner - Mail.app (that is, a user named "nobody"). Further, they acquire one or more users at a time (they shared).

Last edited by KniazidisR (2020-05-19 02:59:12 pm)


Model: MacBook Pro
OS X: Catalina 10.15.4
Web Browser: Safari 13.1
Ram: 4 GB

Offline

 

#5 2020-05-21 03:56:29 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 4344

Re: How to, get the id of an account in Mail?

As some of you already know, I'm stubborn.

As nobody gave a valuable answer to my question, I treated my problem with the deciphering of error messages.

The original problem is that, under Catalina, mdfind prove to be unable to find files of Mail messages.
Here is a script doing the job without triggering mdfind.

Applescript:

#[SCRIPT]
-- Yvan KOENIG (VALLAURIS, France) mercredi 20 mai 2020 12:19:41
-- Edited on 2020/05/22, no longer use AppleScript's text item delimiters
----------------------------------------------------------------
use AppleScript version "2.5"
use framework "Foundation"
use scripting additions
----------------------------------------------------------------

property wantPOSIXPaths : false
-- true --> return a list of lists of POSIX Paths
-- false --> return a list of lists of file objects

property |⌘| : a reference to current application

my Germaine()

on Germaine()
   tell application "Mail"
       set _sel to selection
       log "point 001"
       log _sel (*message id 74176 of mailbox INBOX of account id 8466177C-3C92-4B82-BB40-EA424A398F0B*)
       
       # Use account to find mail-folder in attempt to be compatible back to Snow Leopard.
       set acnt1Dir to (account directory of account 1) as string
       log "point 002"
       log acnt1Dir (*SSD 1000:Users:**********:Library:Mail:V5:2798C56C-FB1E-456F-8E15-30AC6D6C8D30:*)
       set mailFolderURL to |⌘|'s NSURL's fileURLWithPath:(POSIX path of acnt1Dir)
       log "point 003"
       log mailFolderURL as «class furl» (*file SSD 1000:Users:**********:Library:Mail:V5:2798C56C-FB1E-456F-8E15-30AC6D6C8D30:*)
       set mailFolderURL to mailFolderURL's URLByDeletingLastPathComponent()
       log "point 004"
       log mailFolderURL as «class furl» (*file SSD 1000:Users:**********:Library:Mail:V5:*)
   end tell -- Mail
   
   set theMessages to {}
   repeat with _msg in _sel
       set foundMessages to my getMessage(_msg, mailFolderURL)
       set end of theMessages to foundMessages
   end repeat
   return theMessages
end Germaine

#=====

on getMessage(_msg, mailFolderURL)
   tell application "Mail" to tell _msg
       set mID to its id
       log "point 010"
       log mID (*69146*)
       set itsMailBox to its mailbox
       log "point 011"
       log itsMailBox (*mailbox [Gmail]/Tous les messages of account id 2798C56C-FB1E-456F-8E15-30AC6D6C8D30*)
       (*mailbox INBOX of account id 8466177C-3C92-4B82-BB40-EA424A398F0B*)
       (*mailbox fournisseurs/logiciels achetés/Carbon Copy Cloner*)
       try
           itsMailBox * 1 -- will issue an error deciphered below
       on error errmsg
           log "point 012"
           log errmsg (*Impossible de convertir «class mbxp» "[Gmail]/Tous les messages" of «class mact» id "2798C56C-FB1E-456F-8E15-30AC6D6C8D30" of application "Mail" en type number.*)
           set enListe to my splitString:errmsg usingString:quote
           log "point 013"
           log enListe (*Impossible de convertir «class mbxp» , [Gmail]/Tous les messages, of «class mact» id , 2798C56C-FB1E-456F-8E15-30AC6D6C8D30, of application , Mail, en type number.*)
           set boxPath to item 2 of enListe
           log "point 014"
           log boxPath (*[Gmail]/Tous les messages*)
       end try
       if boxPath starts with "[Gmail]/" then
           -- we must retrieve:
           -- "/Users/**********/Library/Mail/V5/2798C56C-FB1E-456F-8E15-30AC6D6C8D30/[Gmail].mbox/Tous les messages.mbox/387AD57C-A952-46C3-83DA-4FFBC58D9679/Data/9/6/Messages/69146.emlx"
           -- so we need to build the path:
           -- "/Users/**********/Library/Mail/V5/2798C56C-FB1E-456F-8E15-30AC6D6C8D30/[Gmail].mbox/Tous les messages.mbox/"
           -- then, the path :
           -- "/Users/**********/Library/Mail/V5/2798C56C-FB1E-456F-8E15-30AC6D6C8D30/[Gmail].mbox/Tous les messages.mbox/387AD57C-A952-46C3-83DA-4FFBC58D9679/"
           set boxID to item 4 of enListe
           log "point 020"
           log boxID (*2798C56C-FB1E-456F-8E15-30AC6D6C8D30*)
           set boxAsList to my splitString:boxPath usingString:"/"
           log "point 021"
           log boxAsList (*[Gmail], Tous les messages*)
           set boxPathPlus to my concatList:boxAsList usingString:".mbox/"
           log "point 022"
           log boxPathPlus (*[Gmail].mbox/Tous les messages*)
       else -- “standard” behavior
           set boxProperties to (get properties of itsMailBox)
           log "point 030"
           log boxProperties
           set itsAccount to get account of boxProperties
           log "point 031"
           log itsAccount --> (*account id 8466177C-3C92-4B82-BB40-EA424A398F0B*) or (*missing value*)
           
           if itsAccount is not missing value then
               -- we must retrieve:
               -- "/Users/**********/Library/Mail/V5/8466177C-3C92-4B82-BB40-EA424A398F0B/INBOX.mbox/387AD57C-A952-46C3-83DA-4FFBC58D9679/Data/4/7/Messages/74176.emlx"
               -- so we need to build the path:
               -- "/Users/**********/Library/Mail/V5/8466177C-3C92-4B82-BB40-EA424A398F0B/INBOX.mbox/"
               -- then, the path :
               -- "/Users/**********/Library/Mail/V5/8466177C-3C92-4B82-BB40-EA424A398F0B/INBOX.mbox/387AD57C-A952-46C3-83DA-4FFBC58D9679/
               set boxID to (get id of account of boxProperties)
               log "point 032"
               log boxID (*8466177C-3C92-4B82-BB40-EA424A398F0B*)
               set boxPathPlus to name of boxProperties
               log "point 033"
               log boxPathPlus (*INBOX*)
           else
               -- we must retrieve:
               -- "/Users/**********/Library/Mail/V5/30ACBF46-881C-40AC-B33B-500D53832270/fournisseurs.mbox/logiciels achetés.mbox/Carbon Copy Cloner.mbox/387AD57C-A952-46C3-83DA-4FFBC58D9679/Data/7/Messages/7837.emlx"
               -- so we need to build the path:
               -- "/Users/**********/Library/Mail/V5/30ACBF46-881C-40AC-B33B-500D53832270/fournisseurs.mbox/logiciels achetés.mbox/Carbon Copy Cloner.mbox/"
               -- then, the path :
               -- "/Users/**********/Library/Mail/V5/30ACBF46-881C-40AC-B33B-500D53832270/fournisseurs.mbox/logiciels achetés.mbox/Carbon Copy Cloner.mbox/387AD57C-A952-46C3-83DA-4FFBC58D9679/
               try
                   itsMailBox * 1 -- will issue an error deciphered below
               on error errmsg
                   log "point 040"
                   log errmsg (*Impossible de convertir «class mbxp» "fournisseurs/logiciels achetés/Carbon Copy Cloner" of application "Mail" en type number.*)
                   set enListe to my splitString:errmsg usingString:quote
                   log "point 041"
                   log enListe (*Impossible de convertir «class mbxp» , fournisseurs/logiciels achetés/Carbon Copy Cloner, of application , Mail, en type number.*)
                   set boxPath to item 2 of enListe
                   log "point 042"
                   log boxPath (*fournisseurs/logiciels achetés/Carbon Copy Cloner*)
                   set boxAsList to my splitString:boxPath usingString:"/"
                   log "point 043"
                   log boxAsList (*fournisseurs, logiciels achetés, Carbon Copy Cloner*)
                   set mainBox to item 1 of boxAsList
                   log "point 044"
                   log mainBox (*fournisseurs*)
                   set boxPathPlus to my concatList:boxAsList usingString:".mbox/"
                   log "point 045"
                   log boxPathPlus (*fournisseurs.mbox/logiciels achetés.mbox/Carbon Copy Cloner*)
               end try
               tell application "Mail" to set theCont to get container of mailbox mainBox
               log "point 046"
               log theCont
               try
                   theCont * 1 -- will issue an error deciphered below
               on error errmsg
                   log "point 047"
                   log errmsg (*Erreur dans Mail : Il est impossible d’obtenir account id "30ACBF46-881C-40AC-B33B-500D53832270".*)
                   set enListe to my splitString:errmsg usingString:quote
                   log "point 048"
                   log enListe (*Erreur dans Mail : Il est impossible d’obtenir account id , 30ACBF46-881C-40AC-B33B-500D53832270, .*)
                   set boxID to item 2 of enListe
                   log "point 049"
                   log boxID (*30ACBF46-881C-40AC-B33B-500D53832270*)
               end try
           end if -- itsAccount is not missing value
       end if -- maybe Gmail
   end tell -- Mail
   set theURL to mailFolderURL's URLByAppendingPathComponent:(boxID & "/" & boxPathPlus & ".mbox")
   log "point 051"
   log theURL as «class furl» (*file SSD 1000:Users:**********:Library:Mail:V5:30ACBF46-881C-40AC-B33B-500D53832270:fournisseurs.mbox:logiciels achetés.mbox:Carbon Copy Cloner.mbox:*)
   set name1 to "/" & mID & ".emlx" -- slash embedded to limit search to the true name when there is no attachment
   log "point 052"
   log name1 (*/7837.emlx*)
   set name2 to "/" & mID & ".partial.emlx" -- slash embedded to limit search to the true name when there is some attachment
   log "point 053"
   log name2 (*/7837.partial.emlx*)
   
   set fileManager to a reference to |⌘|'s NSFileManager's defaultManager()
   set skipsSubdirectoryDescendants to |⌘|'s NSDirectoryEnumerationSkipsSubdirectoryDescendants as integer --> 1
   set skipsPackageDescendants to |⌘|'s NSDirectoryEnumerationSkipsPackageDescendants as integer --> 2
   set skipsHiddenFiles to |⌘|'s NSDirectoryEnumerationSkipsHiddenFiles as integer --> 4
   
   set NSURLIsDirectoryKey to |⌘|'s NSURLIsDirectoryKey
   set keysToRequest to {} --{NSURLIsDirectoryKey}
   
   if (theURL's checkResourceIsReachableAndReturnError:(missing value)) as boolean is false then error "The folder “" & (theURL as «class furl» as string) & "” isn't available."
   set trueURL to theURL
   log "point 054"
   log trueURL as «class furl» (*file SSD 1000:Users:**********:Library:Mail:V5:30ACBF46-881C-40AC-B33B-500D53832270:fournisseurs.mbox:logiciels achetés.mbox:Carbon Copy Cloner.mbox:*)
   set onlyFirstLevelURLs to (fileManager's enumeratorAtURL:theURL includingPropertiesForKeys:keysToRequest options:(skipsSubdirectoryDescendants + skipsPackageDescendants + skipsHiddenFiles) errorHandler:(missing value))'s allObjects()
   log "point 055"
   log onlyFirstLevelURLs as list (*file SSD 1000:Users:**********:Library:Mail:V5:30ACBF46-881C-40AC-B33B-500D53832270:fournisseurs.mbox:logiciels achetés.mbox:Carbon Copy Cloner.mbox:387AD57C-A952-46C3-83DA-4FFBC58D9679:, file SSD 1000:Users:**********:Library:Mail:V5:30ACBF46-881C-40AC-B33B-500D53832270:fournisseurs.mbox:logiciels achetés.mbox:Carbon Copy Cloner.mbox:Info.plist*)
   
   set theFormat to "NOT (self.pathExtension == 'mbox' OR self.pathExtension == 'plist' )" -- to list xx.strings, items which must not be deleted
   set thePredicate to |⌘|'s NSPredicate's predicateWithFormat:theFormat
   set trueURLs to (onlyFirstLevelURLs's filteredArrayUsingPredicate:thePredicate) --as list
   set trueURL to item 1 of trueURLs
   log "point 056"
   log trueURL as «class furl» (*file SSD 1000:Users:**********:Library:Mail:V5:30ACBF46-881C-40AC-B33B-500D53832270:fournisseurs.mbox:logiciels achetés.mbox:Carbon Copy Cloner.mbox:387AD57C-A952-46C3-83DA-4FFBC58D9679:*)
   
   -- Now we may continue to build the path according to the content of mID
   set mID to mID as string
   if (count mID) < 4 then
       set aStr to "Data/Messages/"
   else if (count mID) < 5 then
       set aStr to "Data/" & text item 1 of mID & "/Messages/"
   else if (count mID) < 6 then
       set aStr to "Data/" & text item 2 of mID & "/" & text item 1 of mID & "/Messages/"
   else if (count mID) < 7 then -- I never met such number
       set aStr to "Data/" & text item 3 of mID & "/" & text item 2 of mID & "/" & text item 1 of mID & "/Messages/"
   else if (count mID) < 8 then -- I never met such number
       set aStr to "Data/" & text item 4 of mID & "/" & text item 3 of mID & "/" & text item 2 of mID & "/" & text item 1 of mID & "/Messages/"
   end if
   log "point 057"
   log "mID = " & mID & ", aStr = " & aStr
   (*mID = 216, aStr = Data/Messages/*)
   (*mID = 6216, aStr = Data/6Messages/*)
   (*mID = 75626, aStr = Data/5/7/Messages/*)
   (*mID = 369626, aStr = Data/9/6/3/Messages/*)
   (*mID = 1875626, aStr = Data/5/7/8/1/Messages/*)
   
   set trueURL to trueURL's URLByAppendingPathComponent:aStr
   log "point 058"
   log trueURL as «class furl» (*file SSD 1000:Users:**********:Library:Mail:V5:8466177C-3C92-4B82-BB40-EA424A398F0B:INBOX.mbox:387AD57C-A952-46C3-83DA-4FFBC58D9679:Data:5:7:Messages*)
   -- is there a file whose name is "75626.partial.emlx"
   set maybe to trueURL's URLByAppendingPathComponent:name2
   if (maybe's checkResourceIsReachableAndReturnError:(missing value)) as boolean is false then
       set maybe to trueURL's URLByAppendingPathComponent:name2
       -- is there a file whose name is "75626.emlx"
   else if (maybe's checkResourceIsReachableAndReturnError:(missing value)) as boolean is false then
       error "The file “" & (maybe as «class furl» as string) & "” (or “" & name2 & "” isn't available."
   end if
   
   if wantPOSIXPaths then
       set theMessage to POSIX path of (maybe as «class furl»)
   else
       set theMessage to maybe as «class furl»
   end if
   log "point 059"
   log theMessage (*file SSD 1000:Users:**********:Library:Mail:V5:8466177C-3C92-4B82-BB40-EA424A398F0B:INBOX.mbox:387AD57C-A952-46C3-83DA-4FFBC58D9679:Data:5:7:Messages:75626.emlx*)
   return theMessage
   
   (*
-- At last, scan the content of the pointed folder to grab the file whose name is mID &".emlx" or mID &".partial.emlx"
set allURLs to (fileManager's enumeratorAtURL:trueURL includingPropertiesForKeys:keysToRequest options:(skipsPackageDescendants + skipsHiddenFiles) errorHandler:(missing value))'s allObjects()
log linefeed & "point 070 >>>>>>>>>>>>>>>>>>> SCANNED BOX" & linefeed & (trueURL as «class furl») & linefeed & "The scanned box contain " & (count (allURLs as list)) & " messages" & linefeed

if allURLs is equal to missing value then error (theError's localizedDescription() as text)

set theFormat to "(self.path ENDSWITH '" & name1 & "') OR (self.path ENDSWITH '" & name2 & "')" -- to list xx.strings, items which must not be deleted
set thePredicate to |⌘|'s NSPredicate's predicateWithFormat:theFormat
set theFiles to (allURLs's filteredArrayUsingPredicate:thePredicate) as list

if wantPOSIXPaths then
set thePaths to {}
repeat with aFile in theFiles
set end of thePaths to POSIX path of aFile
end repeat
log "point 080"
log thePaths
return thePaths
else
log "point 081"
log theFiles
return theFiles
end if
*)

end getMessage

#=====

on splitString:someText usingString:d1
   set theString to |⌘|'s NSString's stringWithString:someText
   set theList to theString's componentsSeparatedByString:d1
   return theList as list
end splitString:usingString:

#=====

on concatList:theList usingString:d1
   set anArray to |⌘|'s NSArray's arrayWithArray:theList
   return (anArray's componentsJoinedByString:d1) as text
end concatList:usingString:

#=====
#[/SCRIPT]

If somebody has an idea to drop the trick relying upon error messages to grab some infos, please, let me know it.
As I can't run Catalina, I introduced numerous log instructions which helped the original asker which lives in Japan and me to share the script behavior.
Of course in real life, these instructions may be removed.
Here I left them so that it would be easy to know what must be edited to drop the deciphering of error messages.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) jeudi 21 mai 2020 11:53:27

The script was tested with files "1.emlx" thru "877531.emlx"  (or 123456.partial.emlx")
I don't have greater numbers available.

As it appears that the script using Metadata Lib return nothing under Catalina, I edited a bit my long script to drop the use of text items delimiters.

Last edited by Yvan Koenig (2020-05-22 02:14:38 pm)

Online

 

#6 2020-05-22 03:31:49 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 4344

Re: How to, get the id of an account in Mail?

A message from Shane Stanley in <https://macscripter.net/viewtopic.php?id=47686> remind me the power of its library Metadata Lib.

Using it the wanted search would be achieved with :

Applescript:

use AppleScript version "2.5" -- macOS 10.11 or later
use script "Metadata Lib" version "2.0.2"
use scripting additions

-- Yvan KOENIG (VALLAURIS, France) vendredi 22 mai 2020 10:55:15

my Germaine()

on Germaine()
   tell application "Mail"
       set _sel to selection
       # Use account to find mail-folder in attempt to be compatible back to Snow Leopard.
       set acnt1Dir to (account directory of account 1) as string
       set AppleScript's text item delimiters to {":"}
       set mailFolderPath to POSIX path of (text items 1 thru -3 of acnt1Dir as string)
       set AppleScript's text item delimiters to {""}
   end tell -- Mail
   
   set theMessages to {}
   repeat with _msg in _sel
       set end of theMessages to my getMessage(_msg, mailFolderPath)
   end repeat
   return theMessages
   
end Germaine

on getMessage(_msg, mailFolderPath)
   tell application "Mail" to tell _msg
       set mID to its id
   end tell
   set begName to (mID as string) & "."
   set boxpath to perform search in folders {mailFolderPath} predicate string "kMDItemFSName BEGINSWITH %@" search arguments {begName}
   return boxpath
end getMessage

#=====

Of course, if the query used by Metadata Lib rely upon the same tools than mdfind, this proposal would fail.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) vendredi 22 mai 2020 11:31:32

Last edited by Yvan Koenig (2020-05-22 04:08:33 am)

Online

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)