Re: [AS] Scripter mail

Page principale
Supprimer ce message
Répondre à ce message
Auteur: Yvan KOENIG via Applescript_fr
Date:  
À: Liste AppleScript francophone
CC: Yvan KOENIG
Sujet: Re: [AS] Scripter mail

Bonsoir

Je viens de retrouver deux scripts datant de 2017 utilisant les règles pour enregistrer les pièces jointes.
Ça pourrait servir de point de départ mais je répète que le support des dites règles est pour le moins facétieux.

script #1

using terms from application "Mail"
    on perform mail action with messages theMessages for rule theRule
        -- The folder to save the attachments in (must already exist)

        
        
        -- Save in a sub-folder based on the name of the rule in Mail

        
        set subFolder to name of theRule
        tell application "Finder"
            set attachmentsFolder to ((path to home folder as text) & "Dropbox:Attachments") as text
            if not (exists folder subFolder of folder attachmentsFolder) then
                make new folder at attachmentsFolder with properties {name:subFolder}
            end if
        end tell
        tell application "Mail"

            
            repeat with eachMessage in theMessages

                
                set {year:y, month:m, day:d, hours:h, minutes:min} to eachMessage's date sent
                set timeStamp to ("" & y & "-" & my pad(m as integer) & "-" & my pad(d) & "-" & my pad(h) & "-" & my pad(min))

                
                try
                    -- Save the attachment
                    repeat with theAttachment in eachMessage's mail attachments

                        
                        set originalName to name of theAttachment
                        set savePath to attachmentsFolder & ":" & subFolder & ":" & timeStamp & " " & originalName
                        try
                            save theAttachment in file (savePath)
                        end try
                    end repeat

                    
                    display dialog subFolder
                end try
            end repeat

            
        end tell
    end perform mail action with messages
end using terms from


-- Adds leading zeros to date components
on pad(n)
    return text -2 thru -1 of ("00" & n)
end padd


script #2

(*<pre style="
font-family: Monaco, 'Courier New', Courier, monospace;
font-size: 10px;
font-weight: normal;
margin: 0px;
padding: 5px;
border: 1px solid #000000;
width: 720px; height: 340px;
color: #000000;
background-color: #E6E6EE;
overflow: auto;"
title="this text can be pasted into the AppleScript Editor">
*)
(*
Set a Mail Rule to Save Message and Attachment to Desktop.
To save attachments to another another folder on the desktop (i.e. Attachments) create the folder and then
change tell application "Finder" to set pathToAttachments to (path to desktop folder as string) & "Attachments:"
*)

using terms from application "Mail"
    on perform mail action with messages theMessages
        tell application "Finder" to set ptd to (path to desktop folder) as string
        tell application "Finder" to set pathToAttachments to (path to desktop folder) as string
        tell application "Mail"
            repeat with theMessage in theMessages
                set d_recd to date received of theMessage as string
                set d_recd to ReplaceText(d_recd, ":", " ") of me
                set d_recd to ReplaceText(d_recd, ",", " ") of me
                set theText to content of theMessage
                if theMessage's mail attachments is not {} then
                    repeat with theAttachment in theMessage's mail attachments
                        set theFileName to pathToAttachments & (theMessage's subject) & " (Attachment From " & (theMessage's sender) & " Sent " & d_recd & ")" & space & theAttachment's name
                        try
                            save theAttachment in theFileName
                        on error errnum
                        end try
                    end repeat
                end if
                set theFile to ptd & (theMessage's subject) & " (From " & (theMessage's sender) & " Sent " & d_recd & ")" & ".txt"
                set theFileID to open for access file theFile with write permission
                write theText to theFileID
                close access theFileID
            end repeat
        end tell
    end perform mail action with messages
end using terms from


on ReplaceText(theString, fString, rString)
    set current_Delimiters to text item delimiters of AppleScript
    set AppleScript's text item delimiters to fString
    set sList to every text item of theString
    set AppleScript's text item delimiters to rString
    set newString to sList as string
    set AppleScript's text item delimiters to current_Delimiters
    return newString
end ReplaceText (*</pre>*)



Yvan KOENIG (VALLAURIS, France) lundi 21 octobre 2019 18:15:16



_______________________________________________
Applescript_fr mailing list
Applescript_fr@???
http://listes.patpro.net/mailman/listinfo/applescript_fr