r/o
1
use std::error::Error;
2
3
use lettre::{Transport, message::header::ContentType};
4
5
const URL: &str = "https://www.furaffinity.net/msg/pms/";
6
7
fn main() -> Result<(), Box<dyn Error>> {
8
let cookie = std::env::var("FURPOLL_COOKIE").expect("FURPOLL_COOKIE must be set");
9
let subject = std::env::var("FURPOLL_SUBJECT").expect("FURPOLL_SUBJECT must be set");
10
let from = std::env::var("FURPOLL_FROM").expect("FURPOLL_FROM must be set");
11
let to = std::env::var("FURPOLL_TO").expect("FURPOLL_TO must be set");
12
let smtp_host = std::env::var("SMTP_HOST").expect("SMTP_HOST must be set");
13
14
let client = reqwest::blocking::Client::new();
15
let out = client.get(URL).header("Cookie", cookie).send()?.text()?;
16
17
let mut msg = vec![];
18
if out.matches(r#"class="no-sub""#).count() > 0 {
19
msg.push("Need login again.");
20
} else {
21
if out.matches("note-unread").count() > 0 {
22
msg.push("You've got mail! -- https://www.furaffinity.net/msg/pms/");
23
}
24
25
// Originally was /"\d+ Comment Notifications?"/.
26
if out.matches(" Comment Notification").count() > 0 {
27
msg.push(
28
"You've got a comment reply! -- https://www.furaffinity.net/msg/others/#comments",
29
);
30
}
31
}
32
33
if msg.len() > 0 {
34
let msg = lettre::Message::builder()
35
.from(from.parse()?)
36
.to(to.parse()?)
37
.subject(subject)
38
.header(ContentType::TEXT_PLAIN)
39
.body(msg.join("\n"))?;
40
41
lettre::SmtpTransport::builder_dangerous(smtp_host)
42
.build()
43
.send(&msg)?;
44
}
45
46
Ok(())
47
}
48