diff --git a/examples/repl/cmdline.rs b/examples/repl/cmdline.rs index 926287e8f..49c76e244 100644 --- a/examples/repl/cmdline.rs +++ b/examples/repl/cmdline.rs @@ -11,6 +11,7 @@ use deltachat::dc_tools::*; use deltachat::error::Error; use deltachat::imex::*; use deltachat::job::*; +use deltachat::export_chat::export_chat; use deltachat::location; use deltachat::lot::LotState; use deltachat::message::{self, Message, MessageState, MsgId}; @@ -374,6 +375,7 @@ pub fn dc_cmdline(context: &Context, line: &str) -> Result<(), failure::Error> { pin \n\ unpin \n\ delchat \n\ + export-chat \n\ ===========================Message commands==\n\ listmsgs \n\ msginfo \n\ @@ -868,6 +870,12 @@ pub fn dc_cmdline(context: &Context, line: &str) -> Result<(), failure::Error> { let chat_id = ChatId::new(arg1.parse()?); chat_id.delete(context)?; } + "export-chat" => { + ensure!(!arg1.is_empty(), "Argument missing."); + let chat_id = ChatId::new(arg1.parse()?); + let res = export_chat(context, chat_id); + println!("{:?}", res); + } "msginfo" => { ensure!(!arg1.is_empty(), "Argument missing."); let id = MsgId::new(arg1.parse()?); diff --git a/examples/repl/main.rs b/examples/repl/main.rs index e34deadd8..3b9774490 100644 --- a/examples/repl/main.rs +++ b/examples/repl/main.rs @@ -262,7 +262,7 @@ const DB_COMMANDS: [&str; 11] = [ "housekeeping", ]; -const CHAT_COMMANDS: [&str; 26] = [ +const CHAT_COMMANDS: [&str; 27] = [ "listchats", "listarchived", "chat", @@ -289,6 +289,7 @@ const CHAT_COMMANDS: [&str; 26] = [ "pin", "unpin", "delchat", + "export-chat", ]; const MESSAGE_COMMANDS: [&str; 8] = [ "listmsgs", diff --git a/src/export_chat.rs b/src/export_chat.rs index 9de91124f..1cf042eb1 100644 --- a/src/export_chat.rs +++ b/src/export_chat.rs @@ -57,7 +57,7 @@ pub fn export_chat(context: &Context, chat_id: ChatId) -> ExportChatResult { if let Ok(c) = contact { let profile_img_path: String; if let Some(path) = c.get_profile_image(context) { - profile_img_path = path.to_str().unwrap_or_else(|| "").to_owned(); + profile_img_path = path.file_name().unwrap_or_else(|| std::ffi::OsStr::new("")).to_str().unwrap().to_owned(); // push referenced blobs (avatars) blobs.push(profile_img_path.clone()); } else { @@ -78,10 +78,11 @@ pub fn export_chat(context: &Context, chat_id: ChatId) -> ExportChatResult { } } + // run message_to_html for each message and generate the html that way let mut html_messages:Vec = Vec::new(); for message in messages { if let Ok(msg) = message { - html_messages.push(message_to_html(&context, &chat_authors, msg)); + html_messages.push(message_to_html(&chat_authors, msg)); } else { html_messages.push( format!( @@ -100,18 +101,20 @@ pub fn export_chat(context: &Context, chat_id: ChatId) -> ExportChatResult { } } - // run message_to_html for each message and generate the html that way - // todo chat image, chat name and so on.. // todo option to export locations as kml? + + // todo export message infos and save them to txt files + // (those can be linked from the messages, they are stored in msg_info/[msg-id].txt) + ExportChatResult { html: format!(r#"
    {}
"#, html_messages.join("")), referenced_blobs: blobs, } } -fn message_to_html(ctx: &Context, author_cache: &HashMap, message: Message) -> String { +fn message_to_html(author_cache: &HashMap, message: Message) -> String { let author: &ContactInfo = { if let Some(c) = author_cache.get(&message.get_from_id()) { c @@ -126,7 +129,7 @@ fn message_to_html(ctx: &Context, author_cache: &HashMap, mess r#"
{author_name}
"#, author_name = author.name, @@ -161,11 +164,8 @@ fn message_to_html(ctx: &Context, author_cache: &HashMap, mess diff --git a/src/lib.rs b/src/lib.rs index 922b99500..fa222f80e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -36,7 +36,7 @@ pub mod constants; pub mod contact; pub mod context; mod e2ee; -mod export_chat; +pub mod export_chat; mod imap; pub mod imex; #[macro_use]