fix: do not split "B"-encoded-words at UTF-8 char boundaries#42
Conversation
|
I also tested that it fixes the problem in chatmail/core#7039 |
|
@mdecimus Could you review this? This is the remaining piece of fixing the issue with long unicode group names in Delta Chat: chatmail/core#7039 |
src/headers/text.rs
Outdated
| let chunk = self.text.as_bytes().get(last_pos..pos).unwrap_or_default(); | ||
| base64_encode_mime(chunk, &mut output, true)?; | ||
|
|
||
| output.write_all(b"?=\r\n\t=?utf-8?B?")?; |
There was a problem hiding this comment.
There is some code duplication here, =?utf-8?B? is being written here and also on line 47.
I prefer an approach using an iterator that returns the bytes at their correct offest which are then encoded and wrapped around =?utf-8?B? and ?=.
In fact, I don't think that a custom iterator is needed at all, you could use char_indices (and avoid having to do (ch as i8) >= -0x40), keep track of the offsets and then print the encoded word once you reached the right size.
There was a problem hiding this comment.
I force-pushed the change, now using char_indices.
1cfb664 to
069efe1
Compare
|
I made some changes to the B-encoding function, can you check that it works for you so I can release? |
|
I tested with commit 2ec9d02, it works. Why remove If the function is called with |
Fixes #40