Applescript:从邮件解析

Applescript:从邮件解析,applescript,Applescript,我正在寻找一个applescript,它通过我的邮件获取想要的结果: 电子邮件主题:Registrierung fuer die Badener Hochzeitstage-2587(这里我需要号码) 我需要的电子邮件内容是在“Frau/Herr/Firma”之后的名称,直到下一个“space” 我的php/mysql代码中有一个错误,因此我的数据库中没有这个错误,所以我需要解析大约400封电子邮件 tell application "Mail" set theMessages to mess

我正在寻找一个applescript,它通过我的邮件获取想要的结果:

电子邮件主题:Registrierung fuer die Badener Hochzeitstage-2587(这里我需要号码)

我需要的电子邮件内容是在“Frau/Herr/Firma”之后的名称,直到下一个“space”

我的php/mysql代码中有一个错误,因此我的数据库中没有这个错误,所以我需要解析大约400封电子邮件

tell application "Mail"

set theMessages to message 1 of mailbox "INBOX" of account "Die Badenerhochzeitstage" whose subject begins with "Registrierung fuer"
set theContent to content of theMessages

set someData to paragraphs of theContent
repeat with someData in theContent

    if someData begins with "Firma" then
        set theURL to paragraph of someData
    else
        set theURL to paragraph 10 of theContent -- this works but this line can change weekly
    end if
end repeat

end tell
在这里,我已经尝试过了,但结果只是得到了一些行,而不是我想要的。

试试这个:

   set TID to text item delimiters
set myRecords to {}

set outputFile to quoted form of (POSIX path of ((path to desktop as text) & "LaunchAgent_Alert.txt")) -- represents "MacHD:Users:david:Desktop:result.txt"

tell application "Mail" to set theMessages to every message of mailbox "INBOX" of account "Badener Hochzeitstage" whose subject begins with "Registrierung fuer"

repeat with aMessage in theMessages
   tell application "Mail" to set {mSubject, mContent} to {subject, content} of aMessage
   set AppleScript's text item delimiters to "-"
   set mSubject to text item 2 of mSubject

   set AppleScript's text item delimiters to "Herr/Frau/Firma "
   set mContent to first word of (text item 2 of mContent)

   set end of myRecords to {mSubject & return & mContent & return & return}

end repeat

set myRecords to myRecords as text
do shell script "echo " & myRecords & " > " & outputFile

set text item delimiters to TID
试试这个

set theAccount to "Die Badenerhochzeitstage"
set subjectText to "Registrierung fuer"
set subjectSearch to "-"
set contentSearch to "Frau/Herr/Firma"
set theResults to {}

tell application "Mail"
    try
        set theMessages to messages of mailbox "INBOX" of account theAccount whose subject begins with subjectText
        if theMessages is {} then
            display dialog "No Messages were found which begins with:" & return & subjectText buttons {"OK"} default button 1
            return
        end if

        repeat with aMessage in theMessages
            tell aMessage
                set theSubject to subject
                set theContent to content
            end tell
            set theNumber to my getFirstWordAfterSearchText(subjectSearch, theSubject)
            set theWord to my getFirstWordAfterSearchText(contentSearch, theContent)
            set end of theResults to {theNumber, theWord}
        end repeat
    on error theError
        display dialog theError buttons {"OK"} default button 1
        return
    end try
end tell
return theResults

(*============== SUBROUTINES =================*)
on getFirstWordAfterSearchText(searchString, theText)
    try
        set {tids, AppleScript's text item delimiters} to {AppleScript's text item delimiters, searchString}
        set textItems to text items of theText
        set AppleScript's text item delimiters to tids
        return (first word of (item 2 of textItems))
    on error theError
        return ""
    end try
end getFirstWordAfterSearchText

英雄所见略同;)我不确定这个名字是一个单词还是更多。这很有趣。他确实说了“上到空间”,所以对我来说这是单词1。无论如何,我很高兴他得到了帮助。