简体   繁体   English

使用Applescript搜索Mail.app的邮箱

[英]Search Mailbox of Mail.app with Applescript

I want to be able to search a mailbox in apple's mail.app for a phase or word, then somehow return or copy all of the email addresses from which the emails which have successfully returned from the result of the search have been sent from.. if you get what i mean 我希望能够在Apple的mail.app中搜索邮箱以查找阶段或单词,然后以某种方式返回或复制从中发送已成功从搜索结果中成功返回的电子邮件的所有电子邮件地址。如果你明白我的意思

I thought that the only way to do this is probably applescript but if anyone else knows any other way please tell me :) 我认为唯一的方法可能是applescript,但如果其他人知道其他方法,请告诉我:)

Mail.app doesn't allow searches directly via Applescript but this will do the trick, though it is a bit slow because it has to iterate through each message: Mail.app不允许直接通过Applescript搜索,但是可以做到这一点,尽管它有点慢,因为它必须遍历每条消息:

global searchTerm
property emailList : {}

set searchTerm to "aSearchTerm"

tell application "Mail"

    set theInbox to inbox

    set firstMessage to 1
    set lastMessage to (get count of messages in theInbox)

    repeat with thisMessage from firstMessage to lastMessage
        set currentMessage to message thisMessage of theInbox

        set messageContent to content of currentMessage

        if messageContent contains searchTerm then
            set end of emailList to sender of currentMessage
        end if

    end repeat

end tell

return emailList

you could also invoke a real search in the interface and then collect the items 您还可以在界面中调用真实搜索,然后收集项目

    [Applications launch:@"Mail"];
    [Keyboard command_alt_press:'f'];
    [Keyboard paste:term];


+(void) command_alt_press:(char)c{
    [self runScript:[NSString stringWithFormat:@"tell application \"System Events\" to keystroke \"%c\" using command option down",c]];
}

you seem competent enough to complete the rest of the code. 您似乎有能力完成其余的代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM