IMAP Deleting the original message result in deleting the copied message

0 votes
asked Oct 18, 2016 by pilouk (520 points)

Is there a way to keep the copied message on the server if the original is deleted ?

I'm using gmail here and everytime i delete the original message the copied reference to this email is also deleted. Is there a way to not delete the copid message ?

Thanks !

Applies to: Rebex Secure Mail

1 Answer

0 votes
answered Oct 20, 2016 by Pavel Matyska (9,680 points)

Hi,

I tested your scenario with this code, but it works as expected, the copied message stays where it was copied:

// connect, login and
// get unique id of a message to test copy-delete scenario

// copy test message
ImapCopyResult copyResult = client.CopyMessage(new ImapMessageSet(uniqueID), targetFolder);
Console.WriteLine("Copy result message count: {0}", copyResult.MessageCount);

// see if it is copied
client.SelectFolder(targetFolder);
ImapMessageCollection copiedList = client.GetMessageList(copyResult.GetTargetMessageSet());
Console.WriteLine("Count of messages using copy result's target message set: {0}", copiedList.Count);

// delete original message
Console.WriteLine("Callind Delete on original.");
client.SelectFolder(originalFolder);
client.DeleteMessage(new ImapMessageSet(uniqueID));

// see if copied message is deleted or is still there
client.SelectFolder(targetFolder);
ImapMessageCollection copiedListAfterDelete = client.GetMessageList(copyResult.GetTargetMessageSet());
Console.WriteLine("Count of messages using copy result's target message set after delete: {0}", copiedListAfterDelete.Count);

Can you please share some test code which behaves like you described? And please check your gmail IMAP settings, how it treats copied messages and how the delete operation is performed.

commented Oct 20, 2016 by pilouk (520 points)
Did you try deleting the message on the gmail web browser client ? I don't delete in my application but only copy. I want to leave a copy in the inbox folder. But i remark that the message copied have a reference label to the targetfolder and when deleting either the source or target in the gmail web browser result in deleting both.
commented Oct 20, 2016 by Pavel Matyska (9,680 points)
I did not before, but now I have. And it turned out that you have to not delete whole message, but delete only the "folder label" you want to delete the message from. It seems that all mails on gmail are in one bag and folders are done with labels on each message. This way, the message is stored only once and making a copy means that the message gets new label with target folder name.
commented Oct 20, 2016 by pilouk (520 points)
How can i delete only the  folder label ?
Thanks!
commented Oct 20, 2016 by Pavel Matyska (9,680 points)
Well, this is hard to describe without the picture of opened mail, but I found an article on internet which should help you, it has those pictures and howto's. Please read it here:

http://www.emailoverloadsolutions.com/blog/gmail-inbox-delete-archive
commented Oct 20, 2016 by pilouk (520 points)
Can i delete this label with rebex ?
commented Oct 20, 2016 by Pavel Matyska (9,680 points)
Yes, you can. Google transforms these folder labels to folders in IMAP protocol, so when you call

    client.SelectFolder(originalFolder);
    client.DeleteMessage(new ImapMessageSet(uniqueID));

google remove the folder label as a result of that IMAP operation, that is used in client.DeleteMessage method. This is why the code I posted in my original answer works.
commented Oct 20, 2016 by pilouk (520 points)
edited Oct 20, 2016 by pilouk
So i will need to do this only if this gmail i guess ? because i don't want to delete the original gmail or not
Thanks man for your help !
commented Oct 21, 2016 by Pavel Matyska (9,680 points)
If you use IMAP protocol to access your gmail account and also use it to copy a message and delete the original one (using the code I post in my answer), you do not need to worry about any "google folder label" at all. Google handles it in its IMAP implementation.
...