0

我正在寻找一个通过我的邮件获取所需结果的applescript:

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

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

我的 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

在这里我尝试过,但结果我只得到了一些线条,而不是我想要的。

4

2 回答 2

0

尝试这个...

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
于 2012-10-11T01:25:26.433 回答
0

尝试这个:

   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
于 2012-10-10T20:03:35.497 回答