JXA将消息移到其他文件夹/邮箱 [英] JXA Move a message to a different folder/mailbox

查看:89
本文介绍了JXA将消息移到其他文件夹/邮箱的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我坚持使用Apple的脚本编辑器编写JXA脚本.本质上,我想浏览收件箱文件夹并将超过44天的邮件移动到存档文件夹.我可以找到该帐户以及收件箱和存档邮箱",但是我一生都无法弄清楚如何将这些坏消息转移到新邮箱中.

I'm stuck writing a JXA script using Apple's Script Editor. Essentially, I want to go through my inbox folder and move messages older than 44 days to an archive folder. I'm able to find the account, and my inbox and archive "mailboxes", but I can't for the life of me figure out how to move the darn message to a new mailbox.

这是我到目前为止所拥有的:

Here's what I have so far:

var staleTime = 44;
var countMessages = 0;
var Mail = new Application("Mail")
var accounts = Mail.accounts();
var account;
var found = false;

for (i = 0; i < accounts.length && !found; ++i) {
    if (accounts[i].name().indexOf("xchange") > -1) {
        account = accounts[i];
        found = true;
    }
}

var mailboxes = account.mailboxes();
var inbox;
var archive;

for (i = 0; i < mailboxes.length; ++i) {
    if(mailboxes[i].name().indexOf("nbox") > -1) {
        inbox = mailboxes[i];
    }
    if(mailboxes[i].name().indexOf("rchive") > -1 &&
       mailboxes[i].name().indexOf("CDE") == -1) {
       archive = mailboxes[i];
    }
}

// console.log("mailbox name is: " + inbox.name());

var messages = m inbox.messages();
var fortyFourDaysAgo = new Date();
fortyFourDaysAgo.setDate(fortyFourDaysAgo.getDate() - staleTime);

for (i = 0; i < messages.length; ++i) {
    var dateSent = messages[i].dateSent();
    if(dateSent < fortyFourDaysAgo) {
        // now what???
    }
}

我可以在脚本编辑器的字典帮助中看到Message对象具有邮箱属性,但是以下任何一项似乎都不起作用:

I can see in the dictionary help in script editor that the Message object has a mailbox property, but none of the following seem to work:

messages[i].mailbox = archive;
messages[i].mailbox(archive);

任何帮助将不胜感激.

推荐答案

苹果讨论区并得到了答案.

基本上,替换

// now what???

...和...

Mail.move(messages[i], {to: archive});

实际上,那里的帖子有一种更为简洁的方法,但以上方法也可以.

Actually, the post over there had a more succinct way of doing it, but the above works too.

这篇关于JXA将消息移到其他文件夹/邮箱的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆