0

I am trying to make an email parser in JXA. I was able to do something similar in applescript:

tell application "Mail" to set theMessages to every message of mailbox "Inbox" of account "MyAcount" whose subject is equal to "Search Text"

repeat with aMessage in theMessages
    tell application "Mail" to set {mContent, mDate} to {content, date received} of aMessage
    ......process each mail.....
end repeat

How would I replicate this but in javascript?

Ben Quan
  • 773
  • 11
  • 25

1 Answers1

0

Perhaps with something like this. Hope this helps.

(() => {
    'use strict';

    const
        appMail = Application('Mail'),
        account = appMail.accounts.byName('MyAccount'),
        inbox = account.mailboxes.byName('INBOX'),
        listMessages = inbox.messages.whose({
            subject: 'Search Text'
        })();

    return listMessages.map(x => {
            const [mContent, mDateReceived] = [x.content(), x.dateReceived()];
            ...
        }

    )
})();
RobC
  • 22,977
  • 20
  • 73
  • 80
unlocked2412
  • 111
  • 4