JXA 将消息移动到不同的文件夹/邮箱 [英] JXA Move a message to a different folder/mailbox

查看:29
本文介绍了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.

这是我目前所拥有的:

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);

任何帮助将不胜感激.

推荐答案

Apple 讨论板并得到答复.

本质上,替换

//现在是什么???

...与...

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天全站免登陆