Skip to content

Commit

Permalink
breaking(writer): remove optional_breakpoint system
Browse files Browse the repository at this point in the history
  • Loading branch information
paolobarbolini committed Mar 28, 2024
1 parent 7ccc393 commit fc1b629
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 81 deletions.
18 changes: 9 additions & 9 deletions src/headers/quoted_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use super::{rfc2047, utils, EmailWriter};
///
/// let mut output = String::new();
/// {
/// let mut writer = EmailWriter::new(&mut output, 0, 0, false, false);
/// let mut writer = EmailWriter::new(&mut output, 0, 0, false);
/// email_encoding::headers::quoted_string::encode(input, &mut writer)?;
/// }
/// assert_eq!(output, "John");
Expand All @@ -27,7 +27,7 @@ use super::{rfc2047, utils, EmailWriter};
///
/// let mut output = String::new();
/// {
/// let mut writer = EmailWriter::new(&mut output, 0, 0, false, false);
/// let mut writer = EmailWriter::new(&mut output, 0, 0, false);
/// email_encoding::headers::quoted_string::encode(input, &mut writer)?;
/// }
/// assert_eq!(output, "\"John Smith\"");
Expand All @@ -38,7 +38,7 @@ use super::{rfc2047, utils, EmailWriter};
///
/// let mut output = String::new();
/// {
/// let mut writer = EmailWriter::new(&mut output, 0, 0, false, false);
/// let mut writer = EmailWriter::new(&mut output, 0, 0, false);
/// email_encoding::headers::quoted_string::encode(input, &mut writer)?;
/// }
/// assert_eq!(output, "\"Rogue \\\" User\"");
Expand All @@ -49,7 +49,7 @@ use super::{rfc2047, utils, EmailWriter};
///
/// let mut output = String::new();
/// {
/// let mut writer = EmailWriter::new(&mut output, 0, 0, false, false);
/// let mut writer = EmailWriter::new(&mut output, 0, 0, false);
/// email_encoding::headers::quoted_string::encode(input, &mut writer)?;
/// }
/// assert_eq!(output, "=?utf-8?b?QWRyacOhbg==?=");
Expand Down Expand Up @@ -142,7 +142,7 @@ mod tests {
let line_len = s.len();

{
let mut w = EmailWriter::new(&mut s, line_len, 0, false, false);
let mut w = EmailWriter::new(&mut s, line_len, 0, false);
encode("1234567890abcd", &mut w).unwrap();
}

Expand All @@ -155,7 +155,7 @@ mod tests {
let line_len = s.len();

{
let mut w = EmailWriter::new(&mut s, line_len, 0, false, false);
let mut w = EmailWriter::new(&mut s, line_len, 0, false);
encode("1234567890 abcd", &mut w).unwrap();
}

Expand All @@ -168,7 +168,7 @@ mod tests {
let line_len = s.len();

{
let mut w = EmailWriter::new(&mut s, line_len, 0, false, false);
let mut w = EmailWriter::new(&mut s, line_len, 0, false);
encode("1234567890 abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd", &mut w).unwrap();
}

Expand All @@ -184,7 +184,7 @@ mod tests {
let line_len = s.len();

{
let mut w = EmailWriter::new(&mut s, line_len, 0, false, false);
let mut w = EmailWriter::new(&mut s, line_len, 0, false);
encode("12345\\67890 ab\"cd", &mut w).unwrap();
}

Expand Down Expand Up @@ -214,7 +214,7 @@ mod tests {
let line_len = s.len();

{
let mut w = EmailWriter::new(&mut s, line_len, 0, false, false);
let mut w = EmailWriter::new(&mut s, line_len, 0, false);
encode("12345\\67890 perché ab\"cd", &mut w).unwrap();
}

Expand Down
12 changes: 6 additions & 6 deletions src/headers/rfc2047.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const ENCODING_END_SUFFIX: &str = "?=";
///
/// let mut output = String::new();
/// {
/// let mut writer = EmailWriter::new(&mut output, 0, 0, false, false);
/// let mut writer = EmailWriter::new(&mut output, 0, 0, false);
/// email_encoding::headers::rfc2047::encode(input, &mut writer)?;
/// }
/// assert_eq!(output, "=?utf-8?b?QWRyacOhbg==?=");
Expand Down Expand Up @@ -83,7 +83,7 @@ mod tests {
let line_len = s.len();

{
let mut w = EmailWriter::new(&mut s, line_len, 0, false, false);
let mut w = EmailWriter::new(&mut s, line_len, 0, false);
encode("", &mut w).unwrap();
}

Expand All @@ -96,7 +96,7 @@ mod tests {
let line_len = s.len();

{
let mut w = EmailWriter::new(&mut s, line_len, 0, false, false);
let mut w = EmailWriter::new(&mut s, line_len, 0, false);
encode("abcd", &mut w).unwrap();
}

Expand All @@ -109,7 +109,7 @@ mod tests {
let line_len = s.len();

{
let mut w = EmailWriter::new(&mut s, line_len, 0, false, false);
let mut w = EmailWriter::new(&mut s, line_len, 0, false);
encode("abcdef", &mut w).unwrap();
}

Expand All @@ -122,7 +122,7 @@ mod tests {
let line_len = s.len();

{
let mut w = EmailWriter::new(&mut s, line_len, 0, false, false);
let mut w = EmailWriter::new(&mut s, line_len, 0, false);
encode(&"lettre".repeat(20), &mut w).unwrap();
}

Expand All @@ -142,7 +142,7 @@ mod tests {
let line_len = s.len();

{
let mut w = EmailWriter::new(&mut s, line_len, 0, false, false);
let mut w = EmailWriter::new(&mut s, line_len, 0, false);
encode(&"hétérogénéité".repeat(16), &mut w).unwrap();
}

Expand Down
61 changes: 35 additions & 26 deletions src/headers/rfc2231.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use super::{hex_encoding, utils, EmailWriter, MAX_LINE_LEN};
///
/// let mut output = String::new();
/// {
/// let mut writer = EmailWriter::new(&mut output, 0, 0, false, false);
/// let mut writer = EmailWriter::new(&mut output, 0, 0, false);
/// email_encoding::headers::rfc2231::encode("filename", input, &mut writer)?;
/// }
/// assert_eq!(output, "filename=\"invoice.pdf\"");
Expand All @@ -29,7 +29,7 @@ use super::{hex_encoding, utils, EmailWriter, MAX_LINE_LEN};
///
/// let mut output = String::new();
/// {
/// let mut writer = EmailWriter::new(&mut output, 0, 0, false, false);
/// let mut writer = EmailWriter::new(&mut output, 0, 0, false);
/// email_encoding::headers::rfc2231::encode("filename", input, &mut writer)?;
/// }
/// assert_eq!(
Expand All @@ -47,7 +47,7 @@ use super::{hex_encoding, utils, EmailWriter, MAX_LINE_LEN};
///
/// let mut output = String::new();
/// {
/// let mut writer = EmailWriter::new(&mut output, 0, 0, false, false);
/// let mut writer = EmailWriter::new(&mut output, 0, 0, false);
/// email_encoding::headers::rfc2231::encode("filename", input, &mut writer)?;
/// }
/// assert_eq!(
Expand Down Expand Up @@ -89,6 +89,7 @@ pub fn encode(key: &str, mut value: &str, w: &mut EmailWriter<'_>) -> fmt::Resul
// Doesn't fit line

w.new_line()?;
w.forget_spaces();

let mut i = 0_usize;
loop {
Expand Down Expand Up @@ -120,6 +121,7 @@ pub fn encode(key: &str, mut value: &str, w: &mut EmailWriter<'_>) -> fmt::Resul
// Needs encoding (Parameter Value Character Set and Language Information)

w.new_line()?;
w.forget_spaces();

let mut i = 0_usize;
loop {
Expand Down Expand Up @@ -170,7 +172,8 @@ mod tests {
let line_len = 1;

{
let mut w = EmailWriter::new(&mut s, line_len, 0, true, true);
let mut w = EmailWriter::new(&mut s, line_len, 0, true);
w.space();
encode("filename", "", &mut w).unwrap();
}

Expand All @@ -183,7 +186,8 @@ mod tests {
let line_len = 1;

{
let mut w = EmailWriter::new(&mut s, line_len, 0, true, true);
let mut w = EmailWriter::new(&mut s, line_len, 0, true);
w.space();
encode("filename", "duck.txt", &mut w).unwrap();
}

Expand All @@ -199,7 +203,8 @@ mod tests {
let line_len = 1;

{
let mut w = EmailWriter::new(&mut s, line_len, 0, true, true);
let mut w = EmailWriter::new(&mut s, line_len, 0, true);
w.space();
encode("filename", "du\"ck\\.txt", &mut w).unwrap();
}

Expand All @@ -215,13 +220,14 @@ mod tests {
let line_len = s.len();

{
let mut w = EmailWriter::new(&mut s, line_len, 0, true, true);
let mut w = EmailWriter::new(&mut s, line_len, 0, true);
w.space();
encode(
"filename",
"a-fairly-long-filename-just-to-see-what-happens-when-we-encode-it-will-the-client-be-able-to-handle-it.txt",
&mut w,
)
.unwrap();
"filename",
"a-fairly-long-filename-just-to-see-what-happens-when-we-encode-it-will-the-client-be-able-to-handle-it.txt",
&mut w,
)
.unwrap();
}

assert_eq!(
Expand All @@ -240,7 +246,8 @@ mod tests {
let line_len = s.len();

{
let mut w = EmailWriter::new(&mut s, line_len, 0, true, true);
let mut w = EmailWriter::new(&mut s, line_len, 0, true);
w.space();
encode("filename", "caffè.txt", &mut w).unwrap();
}

Expand All @@ -259,13 +266,14 @@ mod tests {
let line_len = s.len();

{
let mut w = EmailWriter::new(&mut s, line_len, 0, true, true);
let mut w = EmailWriter::new(&mut s, line_len, 0, true);
w.space();
encode(
"filename",
"testing-to-see-what-happens-when-📕📕📕📕📕📕📕📕📕📕📕-are-placed-on-the-boundary.txt",
&mut w,
)
.unwrap();
"filename",
"testing-to-see-what-happens-when-📕📕📕📕📕📕📕📕📕📕📕-are-placed-on-the-boundary.txt",
&mut w,
)
.unwrap();
}

assert_eq!(
Expand All @@ -287,13 +295,14 @@ mod tests {
let line_len = s.len();

{
let mut w = EmailWriter::new(&mut s, line_len, 0, true, true);
let mut w = EmailWriter::new(&mut s, line_len, 0, true);
w.space();
encode(
"filename",
"testing-to-see-what-happens-when-books-are-placed-in-the-second-part-📕📕📕📕📕📕📕📕📕📕📕.txt",
&mut w,
)
.unwrap();
"filename",
"testing-to-see-what-happens-when-books-are-placed-in-the-second-part-📕📕📕📕📕📕📕📕📕📕📕.txt",
&mut w,
)
.unwrap();
}

assert_eq!(
Expand Down Expand Up @@ -323,7 +332,7 @@ mod tests {

let mut output = base_header.clone();
{
let mut w = EmailWriter::new(&mut output, line_len, 0, false, true);
let mut w = EmailWriter::new(&mut output, line_len, 0, true);
encode("filename", &filename, &mut w).unwrap();
}

Expand Down
Loading

0 comments on commit fc1b629

Please sign in to comment.