Applescript да препраща поща с прикачени файлове?

Опитвам се да създам applescript, който ще приема съобщения, които отговарят на определен филтър YYYY), и ще ги препраща към конкретен бележник в Evernote (XXXX), с непокътнат прикачен файл. Досега съм накарал този скрипт да обработва препращането към бележник на Evernote, но изглежда не мога да го накарам да се справя правилно с прикачените файлове.

Как да прикача всички прикачени файлове в имейлите, открити от филтъра (който в идеалния случай би се изпълнявал при получаване на съобщения) към новия препратен имейл?

using terms from application "Mail"
    on perform mail action with messages selection for rule YYYY
        tell application "Mail"
            set theSelection to selection
            set thesubject to subject of item 1 of theSelection
            set theAttachments to every attachment of content of theSelection
            set theForwardedMessage to forward (item 1 of theSelection) with opening window

            tell theForwardedMessage
                make new to recipient at end of to recipients with properties {address:"ZZZZ"}

                set subject to subject of item 1 of theSelection & " @XXXX"
                repeat with a from 1 to length of theAttachments
                    log "message_attachment =" & a
                    make new attacment with properties {filename:a} at after last paragraph
                end repeat
                send
            end tell
        end tell
    end perform mail action with messages
end using terms from

person occam98    schedule 17.09.2013    source източник
comment
Мога ли да попитам защо просто не използвате нормалните правила на Mail.app, за да препратите съобщението. Не го използвам, но предполагам, че препраща прикачените файлове с имейла.   -  person markhunte    schedule 17.09.2013
comment
Също така имам някои искания за това в моя блог. И намерих, ако искате прикачените файлове от един имейл за нова чернова. Първо трябва да бъдат спасени някъде. Цитат от моя блог. Във вашия скрипт не е възможно да получите пътищата на прикачените файлове. Които са необходими за частта ” {file name:theAttachment} ” от скрипта. Тъй като пътищата на прикачените файлове в оригиналния имейл не съществуват по начин, до който можем да стигнем. (не че все пак съм намерил)   -  person markhunte    schedule 17.09.2013
comment
Не използвам нормалните правила за препращане на поща, защото искам да мога да променя темата на съобщението, за да го запиша в бележник на Evernote (чрез @notebook в темата).   -  person occam98    schedule 18.09.2013


Отговори (1)


Изрових сценария, който написах преди малко за някого.

Работи с избраните имейли в Mail.app, запазва прикачените файлове във временната папка на потребителя. след това ги добавя към новия ви имейл. Както казах, не можете AFAIK просто да изтеглите прикачените файлове от оригиналния имейл и да ги поставите в нов имейл.

Не трябва да ви е толкова трудно да преобразувате това обратно в правило за поща.

Така или иначе ще има очевидни неща, които да промените в сценария. Сякаш ще искате да изпрати, а не да отвори и покаже новия имейл. и тяло, обект и т.н.

    #copyright Mark Hunte 2013
--using terms from application "Mail"
--on perform mail action with messages theMessages for rule theRule


-- set up the attachment folder path

set folderName to "temp"
set homePath to (path to temporary items from user domain) as text

set attachmentsFolder to (homePath & folderName) as text


tell application "Mail"
    set theMessages to (get selection)
    repeat with eachMessage in theMessages
        delay 0.5

        -- set up the folder name for this mail message's attachments. We use the time stamp of the  date received time stamp

        set timeStamp to (do shell script "date +%Y_%m_%d_%H%M%S")

        set attachCount to count of (mail attachments of eachMessage)
        if attachCount is not equal to 0 then
            -- use the unix /bin/test command to test if the timeStamp folder  exists. if not then create it and any intermediate directories as required
            if (do shell script "/bin/test -e " & quoted form of ((POSIX path of attachmentsFolder) & "/" & timeStamp) & " ; echo $?") is "1" then
                -- 1 is false
                do shell script "/bin/mkdir -p " & quoted form of ((POSIX path of attachmentsFolder) & "/" & timeStamp)

            end if
            set attachList to {}
            try
                -- Save the attachment

                #SET replaceBadCharsWithUnderscoreInFileNames  TO TRUE  IF YOU WANT BAD CHARACTERS REMOVED FROM THE FILE NAMES THAT MAY STOP THE FILES SAVING DOWN
                set replaceBadCharsWithUnderscoreInFileNames to true
                ####

                repeat with theAttachment in eachMessage's mail attachments
                    if replaceBadCharsWithUnderscoreInFileNames then
                        set originalName to my replaceBadChars((name of theAttachment as string))

                    else
                        set originalName to (name of theAttachment as string)

                    end if



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

                --on error msg
                --display dialog msg
            end try
            set theSubject to "forwarded email"
            set theBody to " body of email "
            set theAddress to "[email protected]"


            set visable to true

            set theForwardedMessage to make new outgoing message with properties {subject:theSubject, content:theBody & return & return}
            tell theForwardedMessage
                set visible to true
                make new to recipient at end of to recipients with properties {address:theAddress} without quote original message

                tell content
                    repeat with i from 1 to the count of attachList
                        set this_file to (item i of attachList as alias)

                        make new attachment with properties {file name:this_file} at after the last paragraph
                    end repeat

                end tell

            end tell



        end if
        delay 0.5
    end repeat

end tell
--end perform mail action with messages
--end using terms from
on replaceBadChars(TEXT_)
    --log TEXT_
    set OkChars to {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "_", ".", "(", ")", "-", ",", space}
    set TEXT_ to characters of TEXT_
    repeat with i from 1 to number of items in TEXT_
        set this_char to item i of TEXT_
        if this_char is not in OkChars then
            set item i of TEXT_ to "_"
        else

        end if
    end repeat
    set TEXT_ to TEXT_ as string

    do shell script " echo " & quoted form of TEXT_
end replaceBadChars
person markhunte    schedule 18.09.2013