summaryrefslogtreecommitdiffstats
path: root/melib/src/email
diff options
context:
space:
mode:
authorManos Pitsidianakis <el13635@mail.ntua.gr>2020-08-25 16:39:12 +0300
committerManos Pitsidianakis <el13635@mail.ntua.gr>2020-08-26 00:54:07 +0300
commit8c6c9806b5bd97142905045fa709d1db3640ac76 (patch)
tree3b4585abff8bb50cfbe98e748eba90d6f5ece603 /melib/src/email
parentfc25c7b165951fb277e218c80e4e1c3e67f1e192 (diff)
Fix some clippy lints
Diffstat (limited to 'melib/src/email')
-rw-r--r--melib/src/email/attachment_types.rs6
-rw-r--r--melib/src/email/attachments.rs67
-rw-r--r--melib/src/email/compose/mime.rs2
-rw-r--r--melib/src/email/parser.rs8
4 files changed, 39 insertions, 44 deletions
diff --git a/melib/src/email/attachment_types.rs b/melib/src/email/attachment_types.rs
index cd9ff817..d1b57cab 100644
--- a/melib/src/email/attachment_types.rs
+++ b/melib/src/email/attachment_types.rs
@@ -209,7 +209,7 @@ impl ContentType {
}
}
- pub fn make_boundary(parts: &Vec<AttachmentBuilder>) -> String {
+ pub fn make_boundary(parts: &[AttachmentBuilder]) -> String {
use crate::email::compose::random::gen_boundary;
let mut boundary = "bzz_bzz__bzz__".to_string();
let mut random_boundary = gen_boundary();
@@ -236,7 +236,7 @@ impl ContentType {
}
}
- boundary.extend(random_boundary.chars());
+ boundary.push_str(&random_boundary);
/* rfc134
* "The only mandatory parameter for the multipart Content-Type is the boundary parameter,
* which consists of 1 to 70 characters from a set of characters known to be very robust
@@ -253,7 +253,7 @@ impl ContentType {
}
}
- pub fn parts(&self) -> Option<&Vec<Attachment>> {
+ pub fn parts(&self) -> Option<&[Attachment]> {
if let ContentType::Multipart { ref parts, .. } = self {
Some(parts)
} else {
diff --git a/melib/src/email/attachments.rs b/melib/src/email/attachments.rs
index 758f89e4..95a604ee 100644
--- a/melib/src/email/attachments.rs
+++ b/melib/src/email/attachments.rs
@@ -200,7 +200,7 @@ impl AttachmentBuilder {
if n.eq_ignore_ascii_case(b"name") {
if let Ok(v) = crate::email::parser::encodings::phrase(v.trim(), false)
.as_ref()
- .and_then(|(_, r)| Ok(String::from_utf8_lossy(r).to_string()))
+ .map(|(_, r)| String::from_utf8_lossy(r).to_string())
{
name = Some(v);
} else {
@@ -529,7 +529,7 @@ impl Attachment {
}
pub fn mime_type(&self) -> String {
- format!("{}", self.content_type).to_string()
+ self.content_type.to_string()
}
pub fn attachments(&self) -> Vec<Attachment> {
let mut ret = Vec::new();
@@ -599,37 +599,35 @@ impl Attachment {
pub fn into_raw(&self) -> String {
let mut ret = String::with_capacity(2 * self.raw.len());
fn into_raw_helper(a: &Attachment, ret: &mut String) {
- ret.extend(
- format!(
- "Content-Transfer-Encoding: {}\n",
- a.content_transfer_encoding
- )
- .chars(),
- );
+ ret.push_str(&format!(
+ "Content-Transfer-Encoding: {}\n",
+ a.content_transfer_encoding
+ ));
match &a.content_type {
ContentType::Text {
kind: _,
parameters,
charset,
} => {
- ret.extend(
- format!("Content-Type: {}; charset={}", a.content_type, charset).chars(),
- );
+ ret.push_str(&format!(
+ "Content-Type: {}; charset={}",
+ a.content_type, charset
+ ));
for (n, v) in parameters {
ret.push_str("; ");
- ret.extend(String::from_utf8_lossy(n).chars());
+ ret.push_str(&String::from_utf8_lossy(n));
ret.push_str("=");
if v.contains(&b' ') {
ret.push_str("\"");
}
- ret.extend(String::from_utf8_lossy(v).chars());
+ ret.push_str(&String::from_utf8_lossy(v));
if v.contains(&b' ') {
ret.push_str("\"");
}
}
ret.push_str("\n\n");
- ret.extend(String::from_utf8_lossy(a.body()).chars());
+ ret.push_str(&String::from_utf8_lossy(a.body()));
}
ContentType::Multipart {
boundary,
@@ -637,42 +635,41 @@ impl Attachment {
parts,
} => {
let boundary = String::from_utf8_lossy(boundary);
- ret.extend(format!("Content-Type: {}; boundary={}", kind, boundary).chars());
+ ret.push_str(&format!("Content-Type: {}; boundary={}", kind, boundary));
if *kind == MultipartType::Signed {
- ret.extend(
- "; micalg=pgp-sha512; protocol=\"application/pgp-signature\"".chars(),
- );
+ ret.push_str("; micalg=pgp-sha512; protocol=\"application/pgp-signature\"");
}
ret.push('\n');
let boundary_start = format!("\n--{}\n", boundary);
for p in parts {
- ret.extend(boundary_start.chars());
+ ret.push_str(&boundary_start);
into_raw_helper(p, ret);
}
- ret.extend(format!("--{}--\n\n", boundary).chars());
+ ret.push_str(&format!("--{}--\n\n", boundary));
}
ContentType::MessageRfc822 => {
- ret.extend(format!("Content-Type: {}\n\n", a.content_type).chars());
- ret.extend(String::from_utf8_lossy(a.body()).chars());
+ ret.push_str(&format!("Content-Type: {}\n\n", a.content_type));
+ ret.push_str(&String::from_utf8_lossy(a.body()));
}
ContentType::PGPSignature => {
- ret.extend(format!("Content-Type: {}\n\n", a.content_type).chars());
- ret.extend(String::from_utf8_lossy(a.body()).chars());
+ ret.push_str(&format!("Content-Type: {}\n\n", a.content_type));
+ ret.push_str(&String::from_utf8_lossy(a.body()));
}
ContentType::OctetStream { ref name } => {
if let Some(name) = name {
- ret.extend(
- format!("Content-Type: {}; name={}\n\n", a.content_type, name).chars(),
- );
+ ret.push_str(&format!(
+ "Content-Type: {}; name={}\n\n",
+ a.content_type, name
+ ));
} else {
- ret.extend(format!("Content-Type: {}\n\n", a.content_type).chars());
+ ret.push_str(&format!("Content-Type: {}\n\n", a.content_type));
}
ret.push_str(&BASE64_MIME.encode(a.body()).trim());
}
_ => {
- ret.extend(format!("Content-Type: {}\n\n", a.content_type).chars());
- ret.extend(String::from_utf8_lossy(a.body()).chars());
+ ret.push_str(&format!("Content-Type: {}\n\n", a.content_type));
+ ret.push_str(&String::from_utf8_lossy(a.body()));
}
}
}
@@ -737,11 +734,9 @@ fn decode_rec_helper<'a>(a: &'a Attachment, filter: &mut Option<Filter<'a>>) ->
match a.content_type {
ContentType::Other { .. } => Vec::new(),
ContentType::Text { .. } => decode_helper(a, filter),
- ContentType::OctetStream { ref name } => name
- .clone()
- .unwrap_or_else(|| a.mime_type())
- .to_string()
- .into_bytes(),
+ ContentType::OctetStream { ref name } => {
+ name.clone().unwrap_or_else(|| a.mime_type()).into_bytes()
+ }
ContentType::PGPSignature => Vec::new(),
ContentType::MessageRfc822 => {
let temp = decode_rfc822(a.body());
diff --git a/melib/src/email/compose/mime.rs b/melib/src/email/compose/mime.rs
index 6ed720d3..755f6250 100644
--- a/melib/src/email/compose/mime.rs
+++ b/melib/src/email/compose/mime.rs
@@ -41,7 +41,7 @@ pub fn encode_header(value: &str) -> String {
*
* Whitespaces inside encoded tokens must be greedily taken,
* instead of splitting each non-ascii word into separate encoded tokens. */
- if !g.split_whitespace().next().is_none() {
+ if g.split_whitespace().next().is_some() {
ret.push_str(&format!(
"=?UTF-8?B?{}?=",
BASE64_MIME
diff --git a/melib/src/email/parser.rs b/melib/src/email/parser.rs
index b9edb174..a5862c93 100644
--- a/melib/src/email/parser.rs
+++ b/melib/src/email/parser.rs
@@ -417,7 +417,7 @@ pub mod headers {
));
}
let mut ptr = 0;
- let mut name: &[u8] = &input[0..0];
+ let mut name: &[u8] = &[];
let mut has_colon = false;
/* field-name = 1*<any CHAR, excluding CTLs, SPACE, and ":"> */
for (i, x) in input.iter().enumerate() {
@@ -573,7 +573,7 @@ pub mod headers {
));
}
let mut ptr = 0;
- let mut name: &[u8] = &input[0..0];
+ let mut name: &[u8] = &[];
/* field-name = 1*<any CHAR, excluding CTLs, SPACE, and ":"> */
for (i, x) in input.iter().enumerate() {
if *x == b':' {
@@ -635,7 +635,7 @@ pub mod headers {
pub fn headers_raw(input: &[u8]) -> IResult<&[u8], &[u8]> {
if input.is_empty() {
return Err(nom::Err::Error(
- (input, format!("headers_raw(): input is empty",)).into(),
+ (input, "headers_raw(): input is empty").into(),
));
}
for i in 0..input.len() {
@@ -1507,7 +1507,7 @@ pub mod address {
{
move |i: I| {
let mut res = SmallVec::new();
- let mut i = i.clone();
+ let mut i = i;
// Parse the first element
match f(i.clone()) {