I've been working on my On_My_Mac handler (below) yesterday afternoon and all this morning. I haven't been able to improve on the old original, but I did make some minor changes. I did discover, using
set mboxName to (name of selMailbox)
that:
The Inbox is named "Inbox" and its sub-mailboxes are named "INBOX";
The Sent mailbox is names "Sent" and its sub-mailboxes begin with "Sent Messages";
The Trash mailbox is named "Trash" and its sub-mailboxes begin with "Deleted Messages";
The Junk mailbox is named "Junk" and its sub-mailboxes begin with "Junk";
The Drafts mailbox is named "Drafts" and its sub-mailboxes begin with "Drafts".
Mailboxes "On My Mac" have no account.
(But I have encountered error messages that seem to refer to an "On My Mac" account.)
And now my question: Isn't there a simple way to determine if a mailbox is "On My Mac"?
(I've been looking for a long time, but have found nothing.)
on On_My_Mac(mbox) -- mbox is a Mail mailbox.
tell application "Mail"
try
set mboxName to (name of mbox) as text
on error
return false -- RSS
end try
if mbox is trash mailbox then return false
if mbox is inbox then return false
if mbox is sent mailbox then return false
if mbox is drafts mailbox then return false
if mbox is junk mailbox then return false
if mbox is outbox then return false
end tell
--
repeat
tell application "Mail"
try
set acnt to (account of mbox)
name of acnt
account type of acnt
return false -- mailboxes On My Mac have no account
end try
end tell
--
if first character of mboxName is in {"I", "D", "J", "N", "O", "S", "T"} then
if mboxName is "INBOX" then return false
if mboxName starts with "Deleted Messages" then return false
if mboxName starts with "Drafts" then return false
if mboxName starts with "Junk" then return false
if mboxName starts with "Notes" then return false
if mboxName starts with "Outbox" then return false
if mboxName starts with "Sent Messages" then return false
if mboxName starts with "ToDos" then return false
end if
--
try
tell application "Mail"
set outerBox to mbox
set mbox to (container of mbox) -- error here if no outer mailbox
set mboxName to (name of mbox) as text
end tell
on error
exit repeat
end try
end repeat
--
return true
end On_My_Mac --------------------------------------