Получить получателя черновика (AppleScript, Mail.app) - PullRequest
1 голос
/ 19 ноября 2011

Я хочу получить получателей (поля "to" и т. Д.) Черновика в папке моего черновика Mail.app с помощью AppleScript.Не могу найти правильный синтаксис для этого.

Спасибо.

Ответы [ 3 ]

0 голосов
/ 28 ноября 2011

Вот код для этого в Scripting Bridge (Какао):

for (MailRecipient *recp in message.recipients) {
                MailToRecipient *theRecipient = [[[mail classForScriptingClass:@"to recipient"] alloc] initWithProperties:[NSDictionary dictionaryWithObjectsAndKeys:recp.address, @"address", nil]];
            }
0 голосов
/ 30 декабря 2015

На самом деле это возможно с чистым AppleScript в отличие от решения Какао, предложенного ранее.Вот фрагмент кода, используемого для получения входных значений поля получателей «TO».

tell application "Mail"
    set draftMessages to every message in drafts mailbox
    set draftMessagesID to {}

    # go through each draft message
    repeat with draftMessage in draftMessages
         set draftMessageID to id of draftMessage as string
         copy draftMessageID to the end of draftMessagesID
    end repeat

    # go through the list of draft message ids and process the most recent item
    if (count of the draftMessagesID) is greater than 1 then
        set sortedDraftMessagesID to the reverse of my sortAlphabetically(the draftMessagesID)
        # get only the first item, as this is the most recent
        set lastDraftMessageID to first item of sortedDraftMessagesID as integer
        # get the most recent draft message
        set draftMessage to first message of drafts mailbox whose id is lastDraftMessageID

        set toAddresees to {}
        repeat with toRecipient in (get to recipients of draftMessage)
            set toName to name of toRecipient
            set toAddress to address of toRecipient
            set toFinal to my composeNameAndAddress(toName, toAddress)
            copy toFinal to end of toAddresees
        end repeat

        # now you have the input values of the TO field
        log toAddresees
    end if
end tell

#handler to compose name and address when one is missing
on composeNameAndAddress(name, address)
    if name is missing value then
        return address
    else
        return name & space & "<" & address & ">"
    end if
end composeNameAndAddress

#handler to sort a list alphabetically
on sortAlphabetically(theList)
    set the indexList to {}
    set the sortedList to {}
    repeat (the number of items in theList) times
        set the lowItem to ""
        repeat with i from 1 to (number of items in theList)
            if i is not in the indexList then
                set thisItem to item i of theList as string
                if the lowItem is "" then
                    set the lowItem to thisItem
                    set the lowItemIndex to i
                else if thisItem comes before the lowItem then
                    set the lowItem to thisItem
                    set the lowItemIndex to i
                end if
            end if
        end repeat
        set the end of sortedList to the lowItem
        set the end of the indexList to the lowItemIndex
    end repeat
    return the sortedList
end sortAlphabetically   

Вы упомянули, что вам нужен конкретный черновик, для этого сценария, который я предположил, что вы можете (дляэкземпляр) получить последний черновик, взяв черновик сообщения с самым высоким ID.Это то, что делает вышеупомянутый скрипт, используя команду reverse с универсальным обработчиком простой сортировки.

0 голосов
/ 25 ноября 2011

Почтовый ящик черновиков содержится в средстве просмотра сообщений. Поскольку сообщения еще не были отправлены, вы не можете получить их «получателям». Однако вы можете получить источник сообщения, который содержит список получателей. Хитрость заключается в том, чтобы затем извлечь получателей из этого текста.

tell application "Mail"
set the_messages to every message in drafts mailbox
repeat with this_message in the_messages
    set message_content to the source of this_message
    log message_content
end repeat
end tell
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...