if (mail is NOT junk) then copy and set as read to-> =AppleMail Rule-

Hello!

Apple Mail has some wonderful rules, but it’s totally lacking a rule for if a mail is NOT junk then do so and so. It currently only has: if a mail IS junk.

Basically what would be cool is if you had an Apple Mail rule that automagically copy any incoming mail that IS NOT marked as junk to a mailbox named “Archive” marked as read.

This would allow you to keep a clean inbox, while having all of your messages archived, which would in turn allow for your smart mailboxes to forever keep tabs on their associated messages, and they wouldn’t be marked as unread, and you could delete the originals that are in your inbox after reading them, and it would forever be a clean inbox!!!

HOORAY!

So, does anyone know how to script an Apple Mail Rule that would:

If mail IS NOT junk, copy and set as read to “Archive” mailbox.

??? Pretty please!

You could add a rule to be invoked on every message, audiowizard - to trigger a script something like:


using terms from application "Mail"
	on perform mail action with messages msgs
		repeat with m in msgs
			if not m's junk mail status then
				set s to m's read status
				set m's read status to true
				duplicate m to mailbox "Archive"
				set m's read status to s
			end if
		end repeat
	end perform mail action with messages
end using terms from


I hope so :slight_smile:

Nice, the copy function works, haven’t gotten any junk yet, so can’t verify that, but the read status doesn’t work. The duplicate remains set as not read. Thanks kai :wink:

Yeah, the brief initial test that I ran worked fine, audiowizard - but further testing shows that, while the method works sometimes here, it doesn’t do so consistently (even with a delay).

Jacques’ idea to zap the duplicates, post-copy, produces much more reliable results - although this slightly more direct variation works equally well for me:


using terms from application "Mail"
	on perform mail action with messages msgs
		tell mailbox "Archive" of application "Mail"
			repeat with m in msgs
				if not m's junk mail status then duplicate m to it
			end repeat
			set read status of messages whose read status is false to true
		end tell
	end perform mail action with messages
end using terms from


I’m good with actionscript, PHP & SQL, this applescript stuff is mystical to me, thank you guys for sharing.

yeeesss the inbox copy retains it’s unread status, the archive copy is set as read!

I haven’t gotten any junkmail yet, but I’ll post back as soon as I do.

THX! :smiley:

You guys should be the ones to setup Apple Mail with this preset rule, it’s super userful.