From 8ff26db4813114aea2c330de53dc3bbe2e082c69 Mon Sep 17 00:00:00 2001 From: Mauro D Date: Mon, 28 Nov 2022 13:03:29 +0000 Subject: [PATCH] Renamed body_html and body_text functions. --- README.md | 8 ++++---- examples/message_parse.rs | 8 ++++---- src/lib.rs | 22 +++++++++++----------- tests/integration_test.rs | 8 ++++---- 4 files changed, 23 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 1ef2d9a..9a6bede 100644 --- a/README.md +++ b/README.md @@ -116,7 +116,7 @@ R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7 // HTML and text body parts are returned conforming to RFC8621, Section 4.1.4 assert_eq!( - message.html_body(0).unwrap(), + message.body_html(0).unwrap(), concat!( "

I was thinking about quitting the “exporting” to ", "focus just on the “importing”,

but then I thought,", @@ -126,7 +126,7 @@ R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7 // HTML parts are converted to plain text (and viceversa) when missing assert_eq!( - message.text_body(0).unwrap(), + message.body_text(0).unwrap(), concat!( "I was thinking about quitting the “exporting” to focus just on the", " “importing”,\nbut then I thought, why not do both? ☺\n" @@ -147,11 +147,11 @@ R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7 // Handles UTF-* as well as many legacy encodings assert_eq!( - nested_message.text_body(0).unwrap(), + nested_message.body_text(0).unwrap(), "ℌ𝔢𝔩𝔭 𝔪𝔢 𝔢𝔵𝔭𝔬𝔯𝔱 𝔪𝔶 𝔟𝔬𝔬𝔨 𝔭𝔩𝔢𝔞𝔰𝔢!" ); assert_eq!( - nested_message.html_body(0).unwrap(), + nested_message.body_html(0).unwrap(), "ℌ𝔢𝔩𝔭 𝔪𝔢 𝔢𝔵𝔭𝔬𝔯𝔱 𝔪𝔶 𝔟𝔬𝔬𝔨 𝔭𝔩𝔢𝔞𝔰𝔢!" ); diff --git a/examples/message_parse.rs b/examples/message_parse.rs index d431577..4f015af 100644 --- a/examples/message_parse.rs +++ b/examples/message_parse.rs @@ -94,7 +94,7 @@ R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7 // HTML and text body parts are returned conforming to RFC8621, Section 4.1.4 assert_eq!( - message.html_body(0).unwrap(), + message.body_html(0).unwrap(), concat!( "

I was thinking about quitting the “exporting” to ", "focus just on the “importing”,

but then I thought,", @@ -104,7 +104,7 @@ R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7 // HTML parts are converted to plain text (and viceversa) when missing assert_eq!( - message.text_body(0).unwrap(), + message.body_text(0).unwrap(), concat!( "I was thinking about quitting the “exporting” to focus just on the", " “importing”,\nbut then I thought, why not do both? ☺\n" @@ -121,11 +121,11 @@ R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7 // Handles UTF-* as well as many legacy encodings assert_eq!( - nested_message.text_body(0).unwrap(), + nested_message.body_text(0).unwrap(), "ℌ𝔢𝔩𝔭 𝔪𝔢 𝔢𝔵𝔭𝔬𝔯𝔱 𝔪𝔶 𝔟𝔬𝔬𝔨 𝔭𝔩𝔢𝔞𝔰𝔢!" ); assert_eq!( - nested_message.html_body(0).unwrap(), + nested_message.body_html(0).unwrap(), "ℌ𝔢𝔩𝔭 𝔪𝔢 𝔢𝔵𝔭𝔬𝔯𝔱 𝔪𝔶 𝔟𝔬𝔬𝔨 𝔭𝔩𝔢𝔞𝔰𝔢!" ); diff --git a/src/lib.rs b/src/lib.rs index 0dc9af3..ded02c1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -195,7 +195,7 @@ //! //! // HTML and text body parts are returned conforming to RFC8621, Section 4.1.4 //! assert_eq!( -//! message.html_body(0).unwrap(), +//! message.body_html(0).unwrap(), //! concat!( //! "

I was thinking about quitting the “exporting” to ", //! "focus just on the “importing”,

but then I thought,", @@ -205,7 +205,7 @@ //! //! // HTML parts are converted to plain text (and viceversa) when missing //! assert_eq!( -//! message.text_body(0).unwrap(), +//! message.body_text(0).unwrap(), //! concat!( //! "I was thinking about quitting the “exporting” to focus just on the", //! " “importing”,\nbut then I thought, why not do both? ☺\n" @@ -226,11 +226,11 @@ //! //! // Handles UTF-* as well as many legacy encodings //! assert_eq!( -//! nested_message.text_body(0).unwrap(), +//! nested_message.body_text(0).unwrap(), //! "ℌ𝔢𝔩𝔭 𝔪𝔢 𝔢𝔵𝔭𝔬𝔯𝔱 𝔪𝔶 𝔟𝔬𝔬𝔨 𝔭𝔩𝔢𝔞𝔰𝔢!" //! ); //! assert_eq!( -//! nested_message.html_body(0).unwrap(), +//! nested_message.body_html(0).unwrap(), //! "ℌ𝔢𝔩𝔭 𝔪𝔢 𝔢𝔵𝔭𝔬𝔯𝔱 𝔪𝔶 𝔟𝔬𝔬𝔨 𝔭𝔩𝔢𝔞𝔰𝔢!" //! ); //! @@ -1248,16 +1248,16 @@ impl<'x> Message<'x> { /// Returns a preview of the message body pub fn body_preview(&self, preview_len: usize) -> Option> { if !self.text_body.is_empty() { - preview_text(self.text_body(0)?, preview_len).into() + preview_text(self.body_text(0)?, preview_len).into() } else if !self.html_body.is_empty() { - preview_html(self.html_body(0)?, preview_len).into() + preview_html(self.body_html(0)?, preview_len).into() } else { None } } - /// Returns the transformed contents an inline HTML body part by position - pub fn html_body(&'x self, pos: usize) -> Option> { + /// Returns a message body part as text/plain + pub fn body_html(&'x self, pos: usize) -> Option> { let part = self.parts.get(*self.html_body.get(pos)?)?; match &part.body { PartType::Html(html) => Some(html.as_ref().into()), @@ -1266,9 +1266,9 @@ impl<'x> Message<'x> { } } - /// Returns the transformed contents an inline text body part by position - pub fn text_body(&'x self, pos: usize) -> Option> { - let part = self.parts.get(*self.html_body.get(pos)?)?; + /// Returns a message body part as text/plain + pub fn body_text(&'x self, pos: usize) -> Option> { + let part = self.parts.get(*self.text_body.get(pos)?)?; match &part.body { PartType::Text(text) => Some(text.as_ref().into()), PartType::Html(html) => Some(html_to_text(html.as_ref()).into()), diff --git a/tests/integration_test.rs b/tests/integration_test.rs index 3cfa0de..dd078d8 100644 --- a/tests/integration_test.rs +++ b/tests/integration_test.rs @@ -100,7 +100,7 @@ R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7 ); assert_eq!( - message.html_body(0).unwrap(), + message.body_html(0).unwrap(), concat!( "

I was thinking about quitting the “exporting” to ", "focus just on the “importing”,

but then I thought,", @@ -109,7 +109,7 @@ R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7 ); assert_eq!( - message.text_body(0).unwrap(), + message.body_text(0).unwrap(), concat!( "I was thinking about quitting the “exporting” to focus just on the", " “importing”,\nbut then I thought, why not do both? ☺\n" @@ -124,12 +124,12 @@ R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7 ); assert_eq!( - nested_message.text_body(0).unwrap(), + nested_message.body_text(0).unwrap(), "ℌ𝔢𝔩𝔭 𝔪𝔢 𝔢𝔵𝔭𝔬𝔯𝔱 𝔪𝔶 𝔟𝔬𝔬𝔨 𝔭𝔩𝔢𝔞𝔰𝔢!" ); assert_eq!( - nested_message.html_body(0).unwrap(), + nested_message.body_html(0).unwrap(), "ℌ𝔢𝔩𝔭 𝔪𝔢 𝔢𝔵𝔭𝔬𝔯𝔱 𝔪𝔶 𝔟𝔬𝔬𝔨 𝔭𝔩𝔢𝔞𝔰𝔢!" );