Mail.app: Its Move command works as Duplicate command?

Hi, all.

I recently encountered strange behavior in Mail.app. My goal was to move all messages from the SENT-box to the INBOX, and count the transferred messages. At the same time, if I request messages from the SENT-box, it returns not only its messages, but those deleted from it too !!!

I found a way to work around this problem by applying the whose deleted status is false filter.

Other strange thing is this: moving (not deleted) messages works as duplicate command!!!

The question is, am I doing something wrong (with the move command), or Mail.app is so strangely programmed. Maybe someone knows more about the move command of this app.

My script so far:


set accountName to "Gmail" -- local name of my Google account
set sourceMailboxName to "[" & accountName & "]/Απεσταλμένα" -- local name of SENT box of my Google account
set destinationMailboxName to "INBOX" -- local name of INBOX box of my Google account

tell application "Mail" to tell account accountName
	-- get only not deleted messages of SENT mailbox 
	tell mailbox sourceMailboxName to set snoozedMessages to messages whose deleted status is false
	repeat with theMessage in snoozedMessages
		set read status of theMessage to false
		move theMessage to mailbox destinationMailboxName
	end repeat
end tell

set messageCount to count of snoozedMessages
if not messageCount = 0 then display notification "" with title "Moved to Inbox" subtitle messageCount & " snoozed messages" as text sound name "Tink"

I can’t test with your system.
Are you getting the same behavior if the source account isn’t a Gmail one?
I ask because, here, I met some differences between Gmail, account and others.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) lundi 18 janvier 2021 10:57:43

I tested now move command within my iCloud account, and it works as expected (as move command). So the problem is only with Google accounts. I tested with this script:


set accountName to "iCloud" -- local name of my iCloud account
set sourceMailboxName to "Sent Messages" -- local name of SENT box of my iCloud account
set destinationMailboxName to "INBOX" -- local name of INBOX box of my iCloud account

tell application "Mail" to tell account accountName
	-- get only not deleted messages of SENT mailbox 
	tell mailbox sourceMailboxName to set snoozedMessages to messages whose deleted status is false
	repeat with theMessage in snoozedMessages
		set read status of theMessage to false
		move theMessage to mailbox destinationMailboxName
	end repeat
end tell

set messageCount to count of snoozedMessages
if not messageCount = 0 then display notification "" with title "Moved to Inbox" subtitle messageCount & " snoozed messages" as text sound name "Tink"

It’s what I feared.
When I receive an email thru Gmail, Mail store it in two locations:
Boite de réception > Gmail
Archives > Gmail (Tous les messages)

It may explain why you get the messages twice.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) lundi 18 janvier 2021 17:20:46

OK, interesting info. Thanks for that. But other problem, with moving the messages from Gmail’s Sent mailbox, remains. Maybe, the messages in this box is mirrored from Archives > Gmail mailbox, somewhat. I repeat, when I move some messages from Gmail’s Sent mailbox using script, they copied instead of moving… When I move manually, Gmail’s Sent mailbox lost those messages as expected.