Skip to content

Commit

Permalink
fix(rfc2047): improve output in some cases
Browse files Browse the repository at this point in the history
  • Loading branch information
paolobarbolini committed Mar 28, 2024
1 parent 33ee23e commit 14104c3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
10 changes: 8 additions & 2 deletions src/headers/rfc2047.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,16 @@ pub fn encode(mut s: &str, w: &mut EmailWriter<'_>) -> fmt::Result {
let mut word =
utils::truncate_to_char_boundary(s, unencoded_remaining_line_len.min(s.len()));
if word.is_empty() {
if wrote {
if wrote || w.has_spaces() {
// No space remaining on this line, go to a new one
w.new_line()?;
w.space();
if !w.has_spaces() {
// The last write before this call to `encode` most
// likely wasn't rfc2047 so we must write a "soft"
// space to let the decoder know we're still within the
// same header
w.space();
}
continue;
}

Expand Down
8 changes: 6 additions & 2 deletions src/headers/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ impl<'a> EmailWriter<'a> {
self.spaces = 0;
}

pub(super) fn has_spaces(&mut self) -> bool {
self.spaces >= 1
}

/// Get the length in bytes of the last line written to the inner writer.
pub fn line_len(&self) -> usize {
self.line_len
Expand Down Expand Up @@ -329,8 +333,8 @@ mod tests {
assert_eq!(
s,
concat!(
"Subject: AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA BBBBBBBBBBBBB =?utf-8?b?cw==?=\r\n",
" =?utf-8?b?w6lsZWN0aW9u?=",
"Subject: AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA BBBBBBBBBBBBB\r\n",
" =?utf-8?b?c8OpbGVjdGlvbg==?=",
)
);
}
Expand Down

0 comments on commit 14104c3

Please sign in to comment.