Re: saving mails...
Re: saving mails...
- Subject: Re: saving mails...
- From: Jean-Christophe Helary via AppleScript-Users <email@hidden>
- Date: Fri, 5 Jun 2020 09:46:50 +0900
Bonjour Yvan,
Petit retour sur ces échanges fructueux.
Le script fonctionne bien quand il est appelé directement à partir de Script
Editor.
Par contre, une fois enregistré en tant qu'application et lancé en tant que
tel, j'obtient systématiquement le message d'erreur suivant, quel que soit le
compte mail dans lequel se trouve le mail sélectionné:
Can’t get item 1 of «class ocid» id «data optr000000000073AB90FF7F0000».
Jean-Christophe
> On May 21, 2020, at 21:08, Yvan KOENIG via AppleScript-Users
> <email@hidden> wrote:
>
> New attempt with a stripped code.
>
> #[SCRIPT]
> -- Yvan KOENIG (VALLAURIS, France) mercredi 20 mai 2020 12:19:41
>
> 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
>
> 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
> set theMessages to {}
> repeat with _msg in _sel
> set foundMessages to my getMessage(_msg, mailFolderPath)
> set end of theMessages to foundMessages
> end repeat
> return theMessages
> end Germaine
>
> on getMessage(_msg, mailFolderPath)
> tell application "Mail" to tell _msg
> set mID to its id
> set itsMailBox to its mailbox
> try
> itsMailBox * 1
> on error errmsg
> set enListe to my decoupe(errmsg, quote)
> set boxPath to item 2 of enListe
> end try
> if boxPath starts with "[Gmail]/" then
> set boxID to item 4 of enListe
> set boxAsList to my decoupe(boxPath, "/")
> set boxPathPlus to my recolle(boxAsList, ".mbox/")
> else
> set boxProperties to (get properties of itsMailBox)
> set itsAccount to get account of boxProperties
> if itsAccount is not missing value then
> set boxID to (get id of account of boxProperties)
> set boxPathPlus to name of boxProperties
> else
> try
> itsMailBox * 1
> on error errmsg
> set enListe to my decoupe(errmsg, quote)
> set boxPath to item 2 of enListe
> set boxAsList to my decoupe(boxPath, "/")
> set mainBox to item 1 of boxAsList
> set boxPathPlus to my recolle(boxAsList, ".mbox/")
> end try
> tell application "Mail" to set theCont to get container of mailbox mainBox
> try
> theCont * 1
> on error errmsg
> set enListe to my decoupe(errmsg, quote)
> set boxID to item 2 of enListe
> end try
> end if
> end if
> end tell
> set theURL to |⌘|'s NSURL's fileURLWithPath:mailFolderPath
> set theURL to theURL's URLByAppendingPathComponent:(boxID & "/" & boxPathPlus
> & ".mbox")
> set name1 to "/" & mID & ".emlx"
> set name2 to "/" & mID & ".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
> set onlyFirstLevelURLs to (fileManager's enumeratorAtURL:theURL
> includingPropertiesForKeys:keysToRequest
> options:(skipsSubdirectoryDescendants + skipsPackageDescendants +
> skipsHiddenFiles) errorHandler:(missing value))'s allObjects()
> set theFormat to "NOT (self.pathExtension == 'mbox' OR self.pathExtension ==
> 'plist' )"
> set thePredicate to |⌘|'s NSPredicate's predicateWithFormat:theFormat
> set trueURLs to onlyFirstLevelURLs's filteredArrayUsingPredicate:thePredicate
> set trueURL to item 1 of trueURLs
> 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
> 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
> 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
>
> set trueURL to trueURL's URLByAppendingPathComponent:aStr
> 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
> 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
> return theMessage
> end getMessage
>
> on decoupe(t, d)
> 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
>
> on recolle(l, d)
> set {oTIDs, AppleScript's text item delimiters} to {AppleScript's text item
> delimiters, d}
> set t to l as text
> set AppleScript's text item delimiters to oTIDs
> return t
> end recolle
> #[/SCRIPT]
>
> Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) jeudi
> 21 mai 2020 14:08:43
>
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> AppleScript-Users mailing list (email@hidden)
> Help/Unsubscribe/Update your Subscription:
> Archives: http://lists.apple.com/archives/applescript-users
>
> This email sent to email@hidden
--
Jean-Christophe Helary @brandelune
http://mac4translators.blogspot.com
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden