Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move sample messages to Rust test #77

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,15 @@ services:
networks: [default]
```

## Sample messages

The `sample` directory contains a couple of test messages. These can be sent using by running:

```sh
cd backend/
cargo test send_sample_messages -- --ignored
```

## Development

Install [Rust](https://www.rust-lang.org/learn/get-started) and [Trunk](https://trunkrs.dev/)
Expand Down
37 changes: 36 additions & 1 deletion backend/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,10 @@ mod test {
use fake::faker::lorem::en::Paragraph;
use fake::faker::name::en::Name;
use fake::Fake;
use lettre::address::Envelope;
use lettre::message::header::ContentType;
use lettre::message::{Attachment, MultiPart, SinglePart};
use lettre::{Message, SmtpTransport, Transport};
use lettre::{Address, Message, SmtpTransport, Transport};
use std::process::{Command, Stdio};
use tokio::time::{sleep, Duration};

Expand Down Expand Up @@ -296,4 +297,38 @@ mod test {
assert!(messages[2].has_plain);
assert_eq!(messages[2].attachments.len(), 1);
}

#[tokio::test]
#[ignore]
async fn send_sample_messages() {
let smtp_port: u16 = parse_env_var("SMTP_PORT", 1025);
let mut paths = std::fs::read_dir("../samples").unwrap();
let mailer = SmtpTransport::builder_dangerous("127.0.0.1".to_string())
.port(smtp_port)
.build();

while let Some(Ok(entry)) = paths.next() {
let message = std::fs::read_to_string(entry.path()).unwrap();
let mut lines = message.lines();

let sender = lines
.next()
.unwrap()
.trim_start_matches("Sender: ")
.parse::<Address>()
.unwrap();
let recipients = lines
.next()
.unwrap()
.trim_start_matches("Recipients: ")
.split(',')
.map(|r| r.trim().parse::<Address>().unwrap())
.collect::<Vec<Address>>();
let envelope = Envelope::new(Some(sender), recipients).unwrap();

let email = lines.collect::<Vec<&str>>().join("\n");

mailer.send_raw(&envelope, email.as_bytes()).unwrap();
}
}
}
12 changes: 0 additions & 12 deletions samples/README.md

This file was deleted.

55 changes: 55 additions & 0 deletions samples/cid.email
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
Sender: [email protected]
Recipients: [email protected]
From: "Fernando Leannon" <[email protected]>
To: "Jacklyn Ebert" <[email protected]>
Date: Thu, 8 Jun 2023 11:33:53 +0200
Subject: CID
Content-Type: multipart/related; boundary="00000000000043999005fd9af451"

--00000000000043999005fd9af451
Content-Type: multipart/alternative; boundary="00000000000043998e05fd9af450"

--00000000000043998e05fd9af450
Content-Type: text/plain; charset="UTF-8"

See:

[image: mailcrab.png]

--00000000000043998e05fd9af450
Content-Type: text/html; charset="UTF-8"

<div dir="ltr">See:<div><br></div><div><img src="cid:ii_limxyp5p0" alt="mailcrab.png" width="32" height="16"><br></div></div>

--00000000000043998e05fd9af450--
--00000000000043999005fd9af451
Content-Type: image/png; name="mailcrab.png"
Content-Disposition: inline; filename="mailcrab.png"
Content-Transfer-Encoding: base64
Content-ID: <ii_limxyp5p0>
X-Attachment-Id: ii_limxyp5p0

iVBORw0KGgoAAAANSUhEUgAAACAAAAAQCAMAAABA3o1rAAAAAXNSR0IArs4c6QAAAotQTFRFAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA+E4AAAAA
AAAAAAAAAAAAAAAAAAAAAAAAPj4+AAAAAAAAAAAAAAAAGgcAAAAAT09PQxMAQUFBPxIANg8ARUVF
WRYAAAAAbiEAo6OjjiwAaiAAcyMAhSkAg4ODgScAXRwAAAAAj4+PQhQAZmZmgikAnjAAdSQAcyMA
FAYAjCsAhSkAgykAPRIAli4AZR8AaRsAlC0AQRUAdx8A9v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V14eUpM8YjUfiAC91EFU9kW18abx/cmNxGFlCPUTm
8vmA5bZGrhyyDfZ2n0/vtJ9uIiWkwO0msPFrVyHbyNkBObW/Re5SUYc+BNCkSnEIWQYOyePRhYuL
FWpJPZZKAi0M/dPKmscQR3D15Hh2AnGmJTw9u1gYaERkhpnuO82IyvX55b2GisI8L+Vv30uiXHmB
QyDI2lcI7j1+9uL12zdCz5/c5+XRkkkVBLhyJ0vsATDxqCn8AKaHfnCNDX0vAUdQtvBoQpv4AAAA
AElFTkSuQmCC
--00000000000043999005fd9af451--
32 changes: 0 additions & 32 deletions samples/multiple_RCPT_TO

This file was deleted.

22 changes: 22 additions & 0 deletions samples/multiple_recipients.email
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Sender: [email protected]
Recipients: [email protected],[email protected],[email protected]
From: "Dayana Doyle" <[email protected]>
To: "Bernita Lockman" <[email protected]>
Subject: Multi-layered motivating productivity
MIME-Version: 1.0
Date: Thu, 08 Jun 2023 09:38:46 +0000
Content-Type: multipart/mixed;
boundary="Db1HKdfCWR11oRoszXnSigQQ3egBUUpR9uKMxmtF"

--Db1HKdfCWR11oRoszXnSigQQ3egBUUpR9uKMxmtF
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: 7bit

quasi voluptatem cum nemo dolorum natus.<br>
ut voluptatem quibusdam quisquam animi sint deleniti id.<br>
esse deserunt magni sit nostrum sit incidunt velit.<br>
expedita quod voluptas quidem nobis et ut et.<br>
quia eius aut est.<br>
rerum voluptatum aspernatur quia.
<p><a href="https://github.com/tweedegolf/mailcrab">external link</a></p>
--Db1HKdfCWR11oRoszXnSigQQ3egBUUpR9uKMxmtF--
36 changes: 36 additions & 0 deletions samples/no_from.email
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
Sender: [email protected]
Recipients: [email protected]
To: "Shawn Pagac" <[email protected]>
Subject: No from header
MIME-Version: 1.0
Date: Thu, 08 Jun 2023 09:35:55 +0000
Content-Type: multipart/mixed;
boundary="Jh2sZ1TLUmW7bbbYGdIIzIV7P83THXwKGWLls1K7"

--Jh2sZ1TLUmW7bbbYGdIIzIV7P83THXwKGWLls1K7
Content-Type: multipart/alternative;
boundary="jLBXq7ZdGMBpk717x9rpw5HM5GYZYZjp3MFaxfMt"

--jLBXq7ZdGMBpk717x9rpw5HM5GYZYZjp3MFaxfMt
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit

nihil reprehenderit id ea.
molestiae non magni numquam et esse eius quod.
et qui eum et voluptatem voluptatum omnis aut necessitatibus.
nemo fugit voluptatibus similique nulla amet.
et veritatis aut est.
qui doloribus neque pariatur.
--jLBXq7ZdGMBpk717x9rpw5HM5GYZYZjp3MFaxfMt
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: 7bit

nihil reprehenderit id ea.<br>
molestiae non magni numquam et esse eius quod.<br>
et qui eum et voluptatem voluptatum omnis aut necessitatibus.<br>
nemo fugit voluptatibus similique nulla amet.<br>
et veritatis aut est.<br>
qui doloribus neque pariatur.
<p><a href="https://github.com/tweedegolf/mailcrab">external link</a></p>
--jLBXq7ZdGMBpk717x9rpw5HM5GYZYZjp3MFaxfMt--
--Jh2sZ1TLUmW7bbbYGdIIzIV7P83THXwKGWLls1K7--
8 changes: 0 additions & 8 deletions samples/no_from.eml

This file was deleted.

37 changes: 37 additions & 0 deletions samples/normal.email
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
Sender: [email protected]
Recipients: [email protected]
From: "Juwan Cruickshank" <[email protected]>
To: "Shawn Pagac" <[email protected]>
Subject: Persistent 24/7 benchmark
MIME-Version: 1.0
Date: Thu, 08 Jun 2023 09:35:55 +0000
Content-Type: multipart/mixed;
boundary="Jh2sZ1TLUmW7bbbYGdIIzIV7P83THXwKGWLls1K7"

--Jh2sZ1TLUmW7bbbYGdIIzIV7P83THXwKGWLls1K7
Content-Type: multipart/alternative;
boundary="jLBXq7ZdGMBpk717x9rpw5HM5GYZYZjp3MFaxfMt"

--jLBXq7ZdGMBpk717x9rpw5HM5GYZYZjp3MFaxfMt
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit

nihil reprehenderit id ea.
molestiae non magni numquam et esse eius quod.
et qui eum et voluptatem voluptatum omnis aut necessitatibus.
nemo fugit voluptatibus similique nulla amet.
et veritatis aut est.
qui doloribus neque pariatur.
--jLBXq7ZdGMBpk717x9rpw5HM5GYZYZjp3MFaxfMt
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: 7bit

nihil reprehenderit id ea.<br>
molestiae non magni numquam et esse eius quod.<br>
et qui eum et voluptatem voluptatum omnis aut necessitatibus.<br>
nemo fugit voluptatibus similique nulla amet.<br>
et veritatis aut est.<br>
qui doloribus neque pariatur.
<p><a href="https://github.com/tweedegolf/mailcrab">external link</a></p>
--jLBXq7ZdGMBpk717x9rpw5HM5GYZYZjp3MFaxfMt--
--Jh2sZ1TLUmW7bbbYGdIIzIV7P83THXwKGWLls1K7--
15 changes: 0 additions & 15 deletions samples/swaks_injects

This file was deleted.