2

Background Users tend to press the 'delete' button in Gmail (or in Outlook via google apps sync), but we want to archive all messages (google clears trash every 30 days).

Solution so far The following script runs on a trigger every hour, moving any threads in trash into the archive.

function archiveTrash() {
var threads = GmailApp.getTrashThreads(0, 100);
for (var i = 0; i < threads.length; i++) {
threads[i].moveToArchive();
}
}

Problem Users are reporting that messages are disappearing from their inboxes.

Probable cause I believe that this is what is happening: the user is dealing with a thread of messages and deletes some messages in the thread (users generally use outlook, so they see each message individually). However other messages in the thread remain in the user's inbox. Then getTrashThreads is picking up threads which contain at least one deleted message, and the script is moving the whole thread to the archive, including the messages which were in the inbox.

Solution? This is where I am stuck. How do I archive only trashed messages, not the whole thread? Is there a way to stop gmail grouping messages into threads at all? Am I even right about what is going on?

user2003974
  • 91
  • 2
  • 5

3 Answers3

0

Gmail only supports archiving at the thread level, not at the message level, but it allows deleting individual messages. I don't think that your use case is supported.

Corey G
  • 7,754
  • 1
  • 28
  • 28
  • 3
    Gmail _per se_ does support archiving at the message level, as in I can turn off conversation view and archive individual messages by clicking buttons. The lack of GmailMessage.MoveToArchive seems to me to be a missing feature, as it means I can't script something I can do by clicking. Do you think this is worth raising in the issue tracker? – user2003974 Jan 24 '13 at 09:26
0

Check if the thread isInInbox(). If it isn't, archive the thread. If it is, archive and then moveToInbox().

Edit: I missed the last part of your question. I don't know of a way to archive specific messages so they don't pop up in their Outlook inbox. You can turn off conversation view in Gmail, but I don't know what effect that has on threads.

Fred
  • 1,081
  • 12
  • 21
  • 2
    Turning off conversation view in Gmail does not appear to have any effect on the opertation of scripts. As far as scripts are concerned the messages are still in threads, they are just shown individually in gmail. – user2003974 Jan 24 '13 at 09:30
0

Not so simple but possible solution:

Set up user ToArchive@YourDomain.com

Iterate through deleted mail checking message ids, not thread, against index of archived messages(more on index later)

Forward messages not in index to ToArcive+messageId@YourDomain.com(before @ can be up to 64 characters so should be ok).

Iterate through messages in ToArchive parsing message id from To: and adding to index then mark as read.

Archive read messages in ToArchive

ScampMichael
  • 3,688
  • 2
  • 16
  • 23
  • Thanks for the answer. I don't want to do anything this complex yet, though I will keep it in mind. If it can't be done in Google Apps Script I'm looking at maybe some VB script in Outlook as a possibility. – user2003974 Jan 24 '13 at 09:28