From 2a5ef8c2ef2d6d64ef9ab8c6216ef68d6f07937c Mon Sep 17 00:00:00 2001 From: Abdo Roig-Maranges Date: Thu, 20 Nov 2014 14:16:48 +0100 Subject: [PATCH] Delete gmail labels header before adding a new one This fixes a bug in which a message ended up with multiple gmail labels header (X-Keywords or so). Fix fix it by removing all labels headers before adding the updated one. Signed-off-by: Abdo Roig-Maranges --- offlineimap/folder/Gmail.py | 4 ++++ offlineimap/folder/GmailMaildir.py | 4 ++++ 2 files changed, 8 insertions(+) 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