103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
-
+
|
}
let re_domains = domains.iter().map(|s| escape(s))
.collect::<Vec<String>>().join("|");
let address = RegexBuilder::new(&format!("^[a-z0-9][a-z0-9.-]*(@({re_domains}))?$"))
.case_insensitive(true).build().stack()?;
Ok(MailServer {
data: vec!(),
data: vec![],
headers: None,
tg,
fields,
address,
})
}
|
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
|
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
|
-
-
-
+
+
+
|
&& let Some(date) = mail.date()
{
reply.push(format!("<u><i>Date:</i></u> <code>{date}</code>"));
}
reply.push("</blockquote><pre>".into());
let reply = reply.join("\n");
let html_parts = mail.html_body_count();
let text_parts = mail.text_body_count();
let attachments = mail.attachment_count();
let text_parts = mail.text_body().len();
let html_parts = mail.html_body().len();
let attachments = mail.attachments().len();
if html_parts != text_parts {
self.tg.debug(&format!("Hm, we have {html_parts} HTML parts and {text_parts} text parts.")).await?;
}
//let mut html_num = 0;
let mut text_num = 0;
let mut file_num = 0;
// let's display first html or text part as body
|
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
|
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
|
-
+
-
+
-
+
-
+
|
* let's just skip html parts for now, they just duplicate text?
while html_num < html_parts {
files_to_send.push(mail.html_part(html_num).stack()?);
html_num += 1;
}
*/
while text_num < text_parts {
files_to_send.push(mail.text_part(text_num.try_into().stack()?)
files_to_send.push(mail.text_body().nth(text_num)
.context("Failed to get text part from message.")?);
text_num += 1;
}
while file_num < attachments {
files_to_send.push(mail.attachment(file_num.try_into().stack()?)
files_to_send.push(mail.attachments().nth(file_num)
.context("Failed to get file part from message.")?);
file_num += 1;
}
for chat in rcpt {
if !files_to_send.is_empty() {
let mut files = vec![];
// let mut first_one = true;
for chunk in &files_to_send {
let data: Vec<u8> = chunk.contents().to_vec();
let data: Vec<u8> = chunk.decoded().to_vec();
let mut filename: Option<String> = None;
for header in chunk.headers() {
if header.name() == "Content-Type" {
if header.raw_name() == "Content-Type" {
match header.value() {
mail_parser::HeaderValue::ContentType(contenttype) => {
if let Some(fname) = contenttype.attribute("name") {
filename = Some(fname.to_owned());
}
},
_ => {
|