aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel GarcĂ­a <[email protected]>2019-03-25 13:09:51 +0100
committerGitHub <[email protected]>2019-03-25 13:09:51 +0100
commitafbfebf659baa4c121f520aa0167184b8e1249d5 (patch)
treeb07b23b35e25bd583d533ae324ab0387519d1c96
parent349cb33fbdd1088aa7da59ec5f49f1a8ed0674c7 (diff)
parent6b686c18f72307e07bca213c0c3fcd13fa02c02c (diff)
downloadvaultwarden-afbfebf659baa4c121f520aa0167184b8e1249d5.tar.gz
vaultwarden-afbfebf659baa4c121f520aa0167184b8e1249d5.zip
Merge pull request #440 from BlackDex/mail-encoding
Fixed long e-mail message extending 1000 lines.
-rw-r--r--Cargo.lock7
-rw-r--r--Cargo.toml1
-rw-r--r--src/mail.rs22
3 files changed, 28 insertions, 2 deletions
diff --git a/Cargo.lock b/Cargo.lock
index e85641e2..bfe7fcea 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -132,6 +132,7 @@ dependencies = [
"num-derive 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)",
"num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
"oath 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "quoted_printable 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"regex 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"reqwest 0.9.12 (registry+https://github.com/rust-lang/crates.io-index)",
"ring 0.13.5 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1603,6 +1604,11 @@ dependencies = [
]
[[package]]
+name = "quoted_printable"
+version = "0.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
name = "r2d2"
version = "0.8.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -2854,6 +2860,7 @@ dependencies = [
"checksum quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9274b940887ce9addde99c4eee6b5c44cc494b182b97e73dc8ffdcb3397fd3f0"
"checksum quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e920b65c65f10b2ae65c831a81a073a89edd28c7cce89475bff467ab4167a"
"checksum quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)" = "cdd8e04bd9c52e0342b406469d494fcb033be4bdbe5c606016defbb1681411e1"
+"checksum quoted_printable 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4126fa98c6d7b166e6a29a24ab96721d618759d803df6a8cb35d6140da475b5a"
"checksum r2d2 0.8.3 (registry+https://github.com/rust-lang/crates.io-index)" = "5d746fc8a0dab19ccea7ff73ad535854e90ddb3b4b8cdce953dd5cd0b2e7bd22"
"checksum rand 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "552840b97013b1a26992c11eac34bdd778e464601a4c2054b5f0bff7c6761293"
"checksum rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)" = "6d71dacdc3c88c1fde3885a3be3fbab9f35724e6ce99467f7d9c5026132184ca"
diff --git a/Cargo.toml b/Cargo.toml
index a5172dd3..b14ba5e3 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -91,6 +91,7 @@ num-derive = "0.2.4"
lettre = "0.9.0"
lettre_email = "0.9.0"
native-tls = "0.2.2"
+quoted_printable = "0.4"
# Template library
handlebars = "1.1.0"
diff --git a/src/mail.rs b/src/mail.rs
index 2a99dbf1..7c4ee324 100644
--- a/src/mail.rs
+++ b/src/mail.rs
@@ -1,8 +1,9 @@
use lettre::smtp::authentication::Credentials;
use lettre::smtp::ConnectionReuseParameters;
use lettre::{ClientSecurity, ClientTlsParameters, SmtpClient, SmtpTransport, Transport};
-use lettre_email::EmailBuilder;
+use lettre_email::{EmailBuilder,PartBuilder,MimeMultipartType};
use native_tls::{Protocol, TlsConnector};
+use quoted_printable::encode_to_str;
use crate::api::EmptyResult;
use crate::auth::{encode_jwt, generate_invite_claims};
@@ -135,11 +136,28 @@ pub fn send_invite_confirmed(address: &str, org_name: &str) -> EmptyResult {
}
fn send_email(address: &str, subject: &str, body_html: &str, body_text: &str) -> EmptyResult {
+ let html = PartBuilder::new()
+ .body(encode_to_str(body_html))
+ .header(("Content-Type", "text/html; charset=utf-8"))
+ .header(("Content-Transfer-Encoding", "quoted-printable"))
+ .build();
+
+ let text = PartBuilder::new()
+ .body(encode_to_str(body_text))
+ .header(("Content-Type", "text/plain; charset=utf-8"))
+ .header(("Content-Transfer-Encoding", "quoted-printable"))
+ .build();
+
+ let alternative = PartBuilder::new()
+ .message_type(MimeMultipartType::Alternative)
+ .child(text)
+ .child(html);
+
let email = EmailBuilder::new()
.to(address)
.from((CONFIG.smtp_from().as_str(), CONFIG.smtp_from_name().as_str()))
.subject(subject)
- .alternative(body_html, body_text)
+ .child(alternative.build())
.build()
.map_err(|e| Error::new("Error building email", e.to_string()))?;