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 <abdo.roig@gmail.com>
This commit is contained in:
Abdo Roig-Maranges 2014-11-20 14:16:48 +01:00
parent fc4c7549d6
commit 2a5ef8c2ef
2 changed files with 8 additions and 0 deletions

View File

@ -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:

View File

@ -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