diff --git a/offlineimap/folder/Gmail.py b/offlineimap/folder/Gmail.py index 2a8afd2..69f0075 100644 --- a/offlineimap/folder/Gmail.py +++ b/offlineimap/folder/Gmail.py @@ -93,6 +93,10 @@ class GmailFolder(IMAPFolder): labels = set() labels = labels - self.ignorelabels labels_str = imaputil.format_labels_string(self.labelsheader, sorted(labels)) + + # First remove old label headers that may be in the message content retrieved + # from gmail Then add a labels header with current gmail labels. + body = self.deletemessageheaders(body, self.labelsheader) body = self.addmessageheader(body, '\n', self.labelsheader, labels_str) if len(body)>200: diff --git a/offlineimap/folder/GmailMaildir.py b/offlineimap/folder/GmailMaildir.py index 7a67c87..3b127d2 100644 --- a/offlineimap/folder/GmailMaildir.py +++ b/offlineimap/folder/GmailMaildir.py @@ -153,7 +153,11 @@ class GmailMaildirFolder(MaildirFolder): # Change labels into content labels_str = imaputil.format_labels_string(self.labelsheader, sorted(labels | ignoredlabels)) + + # First remove old labels header, and then add the new one + content = self.deletemessageheaders(content, self.labelsheader) content = self.addmessageheader(content, '\n', self.labelsheader, labels_str) + rtime = self.messagelist[uid].get('rtime', None) # write file with new labels to a unique file in tmp