OfflineIMAP/offlineimap — pull request #136 by aroig (2014-11-20 10:43:53+00:00)
Title: Fix issue with multiple instances of gmail labels header

This pull request on top of `next` fixes two things reported in Issue #131.

1. Always delete gmail label header before adding a new one, so we do not end up with multiple labels headers.

2. When reading labels from a header, take into account multiple occurrences of the header. Current behavior only looks at the first occurence of the header, but due to the issue fixed in 1 above, multiple instances of the header may already be there.

The end result, is that using this patch would unify the labels headers, and hopefully not loose any labels. Some old explicitly removed labels may pop back up again, though.

I haven't tested it, and I don't have much time to do so at this moment. @altercation, could you do some testing on it, please?

I didn't touch `addmessageheader` in `Base.py`. That function is a bit fragile and full of special cases. A wrong move in there can easily lead to data loss. However, according to the first message in Issue #131, there may still be something wrong in that function...