AppleScript и Mac Mail - извлечение содержимого из тела письма в таблицу Excel - не все извлечения содержимого - PullRequest
0 голосов
/ 03 мая 2018

Использование Applescript Я пытаюсь извлечь основной текст всех электронных писем из определенной папки в Mac Mail в таблицу Excel. Я могу сделать это в какой-то момент с помощью приведенного ниже кода, но по какой-то причине извлекается не весь основной текст (только текст), он обрезается в критической точке, непосредственно перед или в середине захвата целевого адреса электронной почты, типично !

tell application "Microsoft Excel"

    set LinkRemoval to make new workbook

    set theSheet to active sheet of LinkRemoval

    set formula of range "A1" of theSheet to "Date"

end tell





tell application "Mail"

    set theRow to 2

    set theAccount to "Exchange"

    get account theAccount

    set theMessages to messages of mailbox "Inbox/Target Folder" of account "Exchange"

    repeat with aMessage in theMessages

        my SetMessage(content of aMessage, theRow, theSheet)

        set theRow to theRow + 1

    end repeat

end tell



on SetMessage(theMessage, theRow, theSheet)

    tell application "Microsoft Excel"

        set theRange to "A" & theRow

        set formula of range theRange of theSheet to theMessage

    end tell

end SetMessage

Мне сказали, что извлечение его в файл CSV может помочь, но я не знаю, как это сделать с помощью Applescript ... Может ли кто-нибудь помочь? Я новый язык!

Джон

1 Ответ

0 голосов
/ 03 мая 2018

Я предполагаю, что ваша проблема заключается только в извлечении из Почты (а не в Excel). Так что здесь, это будет извлекать содержимое электронной почты из выбора сообщений. Вам необходимо объявить переменные для учетной записи и почтового ящика.

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

on ParseEmailMessages(theMsg)
    tell application "Mail"
        set subj to subject of theMsg
        set DateName to date received of theMsg
        set SenderN to sender of theMsg
        set SenderName to extract name from sender of theMsg
        set senderAddress to extract address from sender of theMsg
        set BodyMessage to content of theMsg
        set IDName to id of theMsg as string
        try
            set RecipientsAddress to address of recipients of theMsg
            set RecipientsName to name of recipients of theMsg
        on error
            set RecipientsN to ""
        end try
        set AttachmentsV to mail attachment of theMsg
    end tell
    set Msg to {subj:subj, RecipientsName:RecipientsName, RecipientsAddress:RecipientsAddress, DateName:DateName, SenderN:SenderN, senderAddress:senderAddress, SenderName:SenderName, BodyMessage:BodyMessage, IDName:IDName, AttachmentsV:AttachmentsV}
    return Msg
end ParseEmailMessages


on run
    tell application "Mail"
        set theMessages to messages of the mailbox TheMailbox of TheAccount
        repeat with i from 1 to count of theMessages
            set theMsg to item i of theMessages
            set Msg to ParseEmailMessages(theMsg)
        end repeat
    end tell
end run

Если вам нужна помощь с Excel, просто дайте мне знать.

...