Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve gmail #266

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

mtalexander
Copy link

This change adds a new option: "skipallmailduplicates" which works much like skipcrossduplicates but applies only to the GMail "All Mail" folder. This is useful for copying gmail to other if most messages have very few GMail labels and you want them to go into a folder for each label, but don't want messages that are labeled to also go into the All Mail folder.

It also changes the gmail to gmail default options to process only the All Mail folder. It already implied sync and resync labels so this is enough to do a full gmail to gmail sync. Everything is in All Mail and this way all messages will be copied and will have all the correct labels.

This option is appropriate when host1 is Gmail and host 2 isn't.
It causes messages in [Gmail]/All Mail to be skipped if they are
in some other folder also.
--gmail1 without --gmail2 implies the new --skipallmailduplicates option.
--gmail2 wihtout --gmail1 doesn't imply --skipcrossduplicates
Both together imply syncing labels and process only [Gmail]/All Mail
@gilleslamiral gilleslamiral self-requested a review January 25, 2021 12:37
@gilleslamiral gilleslamiral self-assigned this Jan 25, 2021
@gilleslamiral gilleslamiral added the Gmail Gmail issues label Jan 25, 2021
@gilleslamiral
Copy link
Member

This change adds a new option: "skipallmailduplicates" which works much like skipcrossduplicates but applies only to the GMail "All Mail" folder. This is useful for copying gmail to other if most messages have very few GMail labels and you want them to go into a folder for each label, but don't want messages that are labeled to also go into the All Mail folder.

I don't get the exact idea so we have to discuss. Let's start with the --gmail1 context: the source is Gmail and the destination is not Gmail, ie, the source has labels/folders but the destination has only folders. The current --gmail1 option makes a message with several labels going only into the first folder/label encountered alphabetically; plus, the "All Mail" folder won't get duplicates since it is treated the last. If I understand your need, you want cross-duplicates, different labels generating duplicates across folders, except for the "All Mail" folder. I don't want to change the --gmail1 behavior with that, duplicates when duplicates were avoided, folders sizes matter, do they? This behavior, different labels generating duplicates across folders except for the "All Mail" folder, is obtained with a sync with no --gmail1 but instead --exclude "All Mail" followed by another sync with --gmail1 but without --exclude "All Mail", this second sync is done to get the messages with no labels at all from "All Mail", if they are some of them. It can be a new option, --skipallmailduplicates is a good name, but I can't put it as a default in --gmail1

It also changes the gmail to gmail default options to process only the All Mail folder. It already implied sync and resync labels so this is enough to do a full gmail to gmail sync. Everything is in All Mail and this way all messages will be copied and will have all the correct labels.

This one could be a very good one but I'm not sure that every message is in "All Mail". I remember having your idea when developing --synclabels --resynclabels but I entered a headache nightmare when noticing Gmail labels behavior across folders.
Maybe Gmail has changed and that currently "All Mail" really contains all emails with all the labels well set to do a good Gmail to Gmail sync but I have to investigate on that.

Anyway thanks for your proposal and your time on it Mike, I appreciate.

@mtalexander
Copy link
Author

mtalexander commented Jan 27, 2021 via email

@gilleslamiral
Copy link
Member

Yes, that's what I want.

Goint point for us!

I wonder how your suggestion works. Won't the second sync for All Mail get all of All Mail, even messages with labels?

No. The second sync performs the "All Mail" after all the other folders. It's --gmail1, it is not --gmail1 --folder "All Mail"

@mtalexander
Copy link
Author

mtalexander commented Jan 28, 2021 via email

@gilleslamiral
Copy link
Member

However this means that the total time for the two runs will be even larger since it scans all mailboxes twice, not just All Mail. It should, however, do what I wanted. I think the new code is equivalent and should take roughly half the time. Mike

I don't think so. Most of the time is spent copying the messages, not getting the folder listings. It will take half the time after the first complete sync, for update runs, but update runs are usually fast.

Thanks anyway, you've seen how imapsync code is a mess and you could deal a little with it :-)

@mtalexander
Copy link
Author

mtalexander commented Jan 29, 2021 via email

@gilleslamiral
Copy link
Member

Hi Mike!

I won't apply your pull request but I wrote a FAQ item about this need in the FAQ.Gmail.txt document.
https://imapsync.lamiral.info/FAQ.d/FAQ.Gmail.txt

Feel free to criticize it.

=======================================================================
Q. The context is a Gmail account at the source, but not Gmail at the
destination. I want cross-duplicates, different Gmail folders/labels
generating duplicate messages across folders on the destination,
except for the "All Mail" folder.

R. This behavior, different Gmail labels generating duplicates across
folders except for the "All Mail" folder, is obtained with a
synchronization with no --gmail1 but instead --exclude "All Mail"
followed by another synchronization with --gmail1 but without
--exclude "All Mail".

  imapsync ... --exclude "All Mail"
  imapsync ... --gmail1

This second sync is done to get the messages with no labels at all
from the folder "All Mail", if they are some of them.

Technically speaking, the first synchronization has not the option
--skipcrossduplicates but the second one has the option
--skipcrossduplicates and it also performs the Gmail "All Mail"
folder/label at the end so only the messages that have no labels will
end up in the "All Mail" destination folder (which is not Gmail,
remember the context).

Thanks to Mike Alexander for this suggestion. 
Mike also provided a patch to implement that directly in imapsync.
See https://github.com/imapsync/imapsync/pull/266
(I refused it because well maintaining it will be very hard for me
and I have other priorities).

=======================================================================

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Gmail Gmail issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants