Yurii Sokolovskyi 2 сар өмнө
parent
commit
bd252a9a68
1 өөрчлөгдсөн 2 нэмэгдсэн , 86 устгасан
  1. 2 86
      src/models.rs

+ 2 - 86
src/models.rs

@@ -1,7 +1,4 @@
-use crate::config::{Config};
-use mail_builder::headers::date::Date;
-use mail_builder::MessageBuilder;
-use mail_parser::{Addr, DateTime, HeaderValue, MimeHeaders, Message};
+use mail_parser::{Addr, DateTime, HeaderValue, Message};
 use std::borrow::Cow;
 use std::path::{PathBuf};
 use sha2::{Sha256, Digest};
@@ -21,8 +18,6 @@ pub struct StrMessage {
     pub from: MailAddress,
     pub date: DateTime,
     pub body: String,
-    pub flowed: bool,
-    pub mailto: String, // mailto link
     pub in_reply_to: Option<String>,
     pub to: Vec<MailAddress>,
     pub cc: Vec<MailAddress>,
@@ -55,80 +50,7 @@ impl std::fmt::Display for MailAddress {
 }
 
 
-impl StrMessage {
-    pub fn pathescape_msg_id(&self) -> PathBuf {
-        // use at your own risk on windows. idk how safe filepaths look there.
-        PathBuf::from(self.id.replace('/', ";"))
-    }
-    // wonky
-    // for some reason mbox is used over eml for things like git, mutt, etc
-    pub fn export_mbox(&self) -> Vec<u8> {
-        let mut message = MessageBuilder::new();
-        if self.flowed {
-            message.format_flowed();
-        }
-        let from = self.from.name.clone().unwrap_or_default();
-        message.message_id(self.id.as_str());
-        message.from((from.as_str(), self.from.address.as_str()));
-        // TODO no alloc. No copy pasta
-
-        fn map_addrs(addrs: &[MailAddress]) -> mail_builder::headers::address::Address<'_> {
-            addrs
-                .iter()
-                .map(|addr| {
-                    (
-                        addr.name.as_ref().map_or("", |s| s.as_str()),
-                        addr.address.as_str(),
-                    )
-                })
-                .collect::<Vec<_>>()
-                .into()
-        }
-
-        message.to(map_addrs(&self.to));
-        message.cc(map_addrs(&self.cc));
-
-        message.header("Date", Date::new(self.date.to_timestamp()));
-        if let Some(irt) = &self.in_reply_to {
-            message.in_reply_to(irt.as_str());
-        }
-        // list-archive
-        message.subject(&self.subject);
-        // Figure out body export and content-transfer...
-        message.text_body(&self.body);
-        // Dummy data for mbox
-        let mut output = Vec::from(&b"From mboxrd@z Thu Jan  1 00:00:00 1970\n"[..]);
-        message.write_to(&mut output).unwrap();
-        // for mbox
-        output.push(b'\n');
-
-        output
-    }
-
-    pub fn mailto(&self, list_name: &str, list_email: &str) -> String {
-        let mut url = format!("mailto:{}?", list_email);
-
-        let from = self.from.address.clone();
-        // make sure k is already urlencoded
-        let mut pushencode = |k: &str, v| {
-            url.push_str(&format!("{}={}&", k, urlencoding::encode(v)));
-        };
-        let fixed_id = format!("<{}>", &self.id);
-        pushencode("cc", &from);
-        pushencode("in-reply-to", &fixed_id);
-        let list_url = format!("{}/{}", &Config::global().base_url, list_name);
-        pushencode("list-archive", &list_url);
-        pushencode("subject", &format!("Re: {}", self.thread_subject));
-        // quoted body
-        url.push_str("body=");
-        for line in self.body.lines() {
-            url.push_str("%3E%20");
-            url.push_str(&urlencoding::encode(line));
-            url.push_str("%0A");
-        }
-        url
-    }
-    
+impl StrMessage {    
     pub fn set_path(&mut self, path: String){
         self.path = path;
     }
@@ -177,10 +99,6 @@ impl StrMessage {
             .body_text(0)
             .unwrap_or(Cow::Borrowed("[No message body]"));
 
-        // life is a nightmare
-        let flowed = msg.content_type()
-            .map_or(false, |x| x.c_type == "flowed");
-
         let mut hasher = Sha256::new();
         let data_to_encode = body.to_string().clone() + &*uid.to_string();
         hasher.update(data_to_encode);
@@ -198,8 +116,6 @@ impl StrMessage {
             thread_subject: thread_subject.to_owned(),
             date,
             body: body.to_string(),
-            flowed,
-            mailto: String::new(),
             in_reply_to,
             uid,
             list