diff options
author | Gaute Hope <eg@gaute.vetsj.com> | 2018-10-19 15:49:24 +0200 |
---|---|---|
committer | Gaute Hope <eg@gaute.vetsj.com> | 2018-10-20 20:46:52 +0200 |
commit | b41f3451448b606a51007b51066fdba080a6a386 (patch) | |
tree | f11fab6ce5e40455d199f3e39214324802c23d6f | |
parent | b06e73af2f70b282267ef1ee5d33364a62997b27 (diff) |
message: move viewable_text to plain_text
-rw-r--r-- | src/compose_message.cc | 3 | ||||
-rw-r--r-- | src/message_thread.cc | 20 | ||||
-rw-r--r-- | src/message_thread.hh | 4 | ||||
-rw-r--r-- | src/modes/forward_message.cc | 2 | ||||
-rw-r--r-- | src/modes/reply_message.cc | 2 | ||||
-rw-r--r-- | src/modes/thread_view/page_client.cc | 2 | ||||
-rw-r--r-- | src/modes/thread_view/thread_view.cc | 6 | ||||
-rw-r--r-- | tests/test_bad_content_id.cc | 4 | ||||
-rw-r--r-- | tests/test_composed_message.cc | 6 | ||||
-rw-r--r-- | tests/test_convert_error.cc | 4 | ||||
-rw-r--r-- | tests/test_crypto.cc | 10 | ||||
-rw-r--r-- | tests/test_markdown.cc | 2 | ||||
-rw-r--r-- | tests/test_mime_message.cc | 2 | ||||
-rw-r--r-- | tests/test_no_newline_msg.cc | 23 | ||||
-rw-r--r-- | tests/test_non_existant_file.cc | 2 |
15 files changed, 43 insertions, 49 deletions
diff --git a/src/compose_message.cc b/src/compose_message.cc index b6a1a25..20d23dd 100644 --- a/src/compose_message.cc +++ b/src/compose_message.cc @@ -283,8 +283,7 @@ namespace Astroid { set_subject (msg.subject); - body << msg.viewable_text (false); - + body << msg.plain_text (false); } void ComposeMessage::finalize () { diff --git a/src/message_thread.cc b/src/message_thread.cc index 2366ac3..134ccd1 100644 --- a/src/message_thread.cc +++ b/src/message_thread.cc @@ -300,21 +300,12 @@ namespace Astroid { root = refptr<Chunk>(new Chunk (g_mime_message_get_mime_part (message))); } - ustring Message::viewable_text (bool html, bool fallback_html) { - /* build message body: - * html: output html (using gmimes html filter) - * - */ - + ustring Message::plain_text (bool fallback_html) { if (missing_content) { LOG (warn) << "message: missing content, no text."; return ""; } - if (html && fallback_html) { - throw logic_error ("message: html implies fallback_html"); - } - ustring body; function< void (refptr<Chunk>) > app_body = @@ -324,13 +315,13 @@ namespace Astroid { bool use = false; if (c->siblings.size() >= 1) { - if (c->is_content_type ("text", html ? "html" : "plain")) { + if (c->is_content_type ("text", "plain") || fallback_html) { use = true; } else { /* check if there are any other preferred */ if (all_of (c->siblings.begin (), c->siblings.end (), - [html](refptr<Chunk> c) { return !c->is_content_type ("text", html ? "html" : "plain"); })) { + [fallback_html](refptr<Chunk> c) { return !(c->is_content_type ("text", "plain") || fallback_html); })) { use = true; } else { use = false; @@ -341,8 +332,9 @@ namespace Astroid { } if (use) { - if (c->viewable && (c->is_content_type ("text", html ? "html" : "plain") || fallback_html)) { - body += c->viewable_text (html); + if (c->viewable && (c->is_content_type ("text", "plain") || fallback_html)) { + /* will output html if HTML part */ + body += c->viewable_text (false); } for_each (c->kids.begin(), diff --git a/src/message_thread.hh b/src/message_thread.hh index 248fdf9..15c8075 100644 --- a/src/message_thread.hh +++ b/src/message_thread.hh @@ -63,10 +63,10 @@ namespace Astroid { ustring date (); ustring date_asctime (); ustring pretty_date (); - ustring pretty_verbose_date (bool = false); + ustring pretty_verbose_date (bool include_short = false); std::vector<ustring> tags; - ustring viewable_text (bool, bool fallback_html = false); + ustring plain_text (bool fallback_html = false); std::vector<refptr<Chunk>> attachments (); refptr<Chunk> get_chunk_by_id (int id); diff --git a/src/modes/forward_message.cc b/src/modes/forward_message.cc index a47adc1..8343b42 100644 --- a/src/modes/forward_message.cc +++ b/src/modes/forward_message.cc @@ -67,7 +67,7 @@ namespace Astroid { quoted << "Cc: " << AddressList(msg->cc()).str () << endl; quoted << endl; - string vt = msg->viewable_text(false); + string vt = msg->plain_text (false); quoted << vt; body = ustring(quoted.str()); diff --git a/src/modes/reply_message.cc b/src/modes/reply_message.cc index c3b673d..4cad1a5 100644 --- a/src/modes/reply_message.cc +++ b/src/modes/reply_message.cc @@ -56,7 +56,7 @@ namespace Astroid { quoted << quoting_a.raw () << endl; - string vt = msg->viewable_text(false); + string vt = msg->plain_text (false); stringstream sstr (vt); while (sstr.good()) { string line; diff --git a/src/modes/thread_view/page_client.cc b/src/modes/thread_view/page_client.cc index a1b7977..82c95a5 100644 --- a/src/modes/thread_view/page_client.cc +++ b/src/modes/thread_view/page_client.cc @@ -455,7 +455,7 @@ namespace Astroid { /* set preview */ { - ustring bp = m->viewable_text (false, false); + ustring bp = m->plain_text (false); if (static_cast<int>(bp.size()) > MAX_PREVIEW_LEN) bp = bp.substr(0, MAX_PREVIEW_LEN - 3) + "..."; diff --git a/src/modes/thread_view/thread_view.cc b/src/modes/thread_view/thread_view.cc index 16d8ba6..9843cde 100644 --- a/src/modes/thread_view/thread_view.cc +++ b/src/modes/thread_view/thread_view.cc @@ -1153,7 +1153,7 @@ namespace Astroid { for (auto &m : mthread->messages) { MessageState s = state[m]; if (s.marked) { - y += m->viewable_text (false, true); + y += m->plain_text (true); y += "\n"; } } @@ -1709,7 +1709,7 @@ namespace Astroid { auto cp = Gtk::Clipboard::get (astroid->clipboard_target); ustring t; - t = focused_message->viewable_text (false, true); + t = focused_message->plain_text (true); cp->set_text (t); } @@ -1739,7 +1739,7 @@ namespace Astroid { auto cp = Gtk::Clipboard::get (astroid->clipboard_target); ustring t; - t = focused_message->viewable_text (false, true); + t = focused_message->plain_text (true); cp->set_text (t); } diff --git a/tests/test_bad_content_id.cc b/tests/test_bad_content_id.cc index fbffa58..70b9064 100644 --- a/tests/test_bad_content_id.cc +++ b/tests/test_bad_content_id.cc @@ -30,7 +30,7 @@ BOOST_AUTO_TEST_SUITE(Reading) Message m (fname); - BOOST_CHECK_NO_THROW (m.viewable_text (true)); + BOOST_CHECK_NO_THROW (m.plain_text (true)); /* the first part is probablematic */ /* refptr<Chunk> c = m.root->kids[0]; */ @@ -60,7 +60,7 @@ BOOST_AUTO_TEST_SUITE(Reading) Message m (fname); - BOOST_CHECK_NO_THROW (m.viewable_text (true)); + BOOST_CHECK_NO_THROW (m.plain_text (true)); /* the first part is probablematic */ /* refptr<Chunk> c = m.root->kids[0]; */ diff --git a/tests/test_composed_message.cc b/tests/test_composed_message.cc index e148a3b..b9411d4 100644 --- a/tests/test_composed_message.cc +++ b/tests/test_composed_message.cc @@ -45,7 +45,7 @@ BOOST_AUTO_TEST_SUITE(Composing) Message m (fn); - ustring rbdy = m.viewable_text (false); + ustring rbdy = m.plain_text (false); BOOST_CHECK_MESSAGE (bdy == rbdy, "message reading produces the same output as compose message input"); @@ -143,7 +143,7 @@ BOOST_AUTO_TEST_SUITE(Composing) BOOST_CHECK (m.subject == subject); BOOST_CHECK (AddressList(m.to()).str () == to); BOOST_CHECK (m.mid == id); - BOOST_CHECK (m.viewable_text (false) == (body + signature)); + BOOST_CHECK (m.plain_text (false) == (body + signature)); unlink (fname.c_str ()); } @@ -175,7 +175,7 @@ BOOST_AUTO_TEST_SUITE(Composing) Message m (fn); - ustring rbdy = m.viewable_text (false); + ustring rbdy = m.plain_text (false); BOOST_CHECK_MESSAGE (bdy == rbdy, "message reading produces the same output as compose message input"); diff --git a/tests/test_convert_error.cc b/tests/test_convert_error.cc index 3f0cf5b..0b4b707 100644 --- a/tests/test_convert_error.cc +++ b/tests/test_convert_error.cc @@ -24,7 +24,7 @@ BOOST_AUTO_TEST_SUITE(Reading) Astroid::Message m (fname); - BOOST_CHECK_NO_THROW (m.viewable_text (false)); + BOOST_CHECK_NO_THROW (m.plain_text (false)); teardown (); } @@ -45,7 +45,7 @@ BOOST_AUTO_TEST_SUITE(Reading) quoted << quoting_a.raw () << endl; - std::string vt = msg.viewable_text(false); + std::string vt = msg.plain_text(false); std::stringstream sstr (vt); while (sstr.good()) { std::string line; diff --git a/tests/test_crypto.cc b/tests/test_crypto.cc index eec324a..d8a4b19 100644 --- a/tests/test_crypto.cc +++ b/tests/test_crypto.cc @@ -69,7 +69,7 @@ BOOST_AUTO_TEST_SUITE(GPGEncryption) delete c; Message m (fn); - ustring rbdy = m.viewable_text (false); + ustring rbdy = m.plain_text (false); BOOST_CHECK_MESSAGE (bdy == rbdy, "message reading produces the same output as compose message input"); @@ -116,7 +116,7 @@ BOOST_AUTO_TEST_SUITE(GPGEncryption) Message m (fn); - ustring rbdy = m.viewable_text (false); + ustring rbdy = m.plain_text (false); BOOST_CHECK_MESSAGE (bdy == rbdy, "message reading produces the same output as compose message input"); @@ -218,7 +218,7 @@ BOOST_AUTO_TEST_SUITE(GPGEncryption) } /* check that body matches */ - ustring rbdy = m->viewable_text (false); + ustring rbdy = m->plain_text (false); BOOST_CHECK_MESSAGE (bdy == rbdy, "message reading produces the same output as compose message input"); /* notmuch thread id */ @@ -251,7 +251,7 @@ BOOST_AUTO_TEST_SUITE(GPGEncryption) Db db (Db::DATABASE_READ_ONLY); mthread->load_messages (&db); - BOOST_CHECK_MESSAGE (bdy == mthread->messages[0]->viewable_text (false), "message body matches composed message"); + BOOST_CHECK_MESSAGE (bdy == mthread->messages[0]->plain_text (false), "message body matches composed message"); tries++; } @@ -321,7 +321,7 @@ BOOST_AUTO_TEST_SUITE(GPGEncryption) delete c; Message m (fn); - ustring rbdy = m.viewable_text (false); + ustring rbdy = m.plain_text (false); BOOST_CHECK_MESSAGE (bdy == rbdy, "message reading produces the same output as compose message input"); diff --git a/tests/test_markdown.cc b/tests/test_markdown.cc index 509159a..0ac8847 100644 --- a/tests/test_markdown.cc +++ b/tests/test_markdown.cc @@ -35,7 +35,7 @@ BOOST_AUTO_TEST_SUITE(Markdown) Message m (fn); /* check plain text part */ - ustring pbdy = m.viewable_text (false); + ustring pbdy = m.plain_text (false); BOOST_CHECK_MESSAGE (pbdy == bdy, "plain text matches plain text"); /* check html part */ diff --git a/tests/test_mime_message.cc b/tests/test_mime_message.cc index 80d5db9..2dc0a56 100644 --- a/tests/test_mime_message.cc +++ b/tests/test_mime_message.cc @@ -27,7 +27,7 @@ BOOST_AUTO_TEST_SUITE(Reading) Message m (fname); - BOOST_CHECK_NO_THROW (m.viewable_text (true)); + BOOST_CHECK_NO_THROW (m.plain_text (true)); teardown (); } diff --git a/tests/test_no_newline_msg.cc b/tests/test_no_newline_msg.cc index d06220f..3931df9 100644 --- a/tests/test_no_newline_msg.cc +++ b/tests/test_no_newline_msg.cc @@ -23,11 +23,12 @@ BOOST_AUTO_TEST_SUITE(Reading) Message m (fname); - ustring text = m.viewable_text(false); + ustring text = m.plain_text(false); BOOST_CHECK (text.find ("line-ignored") != ustring::npos); - ustring html = m.viewable_text(true); - BOOST_CHECK (html.find ("line-ignored") != ustring::npos); + /* test obsolete: */ + /* ustring html = m.viewable_text(true); */ + /* BOOST_CHECK (html.find ("line-ignored") != ustring::npos); */ teardown (); } @@ -46,11 +47,12 @@ BOOST_AUTO_TEST_SUITE(Reading) Message m (fname); - ustring text = m.viewable_text(false); + ustring text = m.plain_text (false); BOOST_CHECK (text.find ("line-ignored.com") != ustring::npos); - ustring html = m.viewable_text(true); - BOOST_CHECK (html.find ("line-ignored.com") != ustring::npos); + /* test obsolete: */ + /* ustring html = m.viewable_text(true); */ + /* BOOST_CHECK (html.find ("line-ignored.com") != ustring::npos); */ teardown (); @@ -66,11 +68,12 @@ BOOST_AUTO_TEST_SUITE(Reading) Message m (fname); - ustring text = m.viewable_text(false); + ustring text = m.plain_text (false); BOOST_CHECK (text.find ("line-ignored.com") != ustring::npos); - ustring html = m.viewable_text(true); - BOOST_CHECK (html.find ("line-ignored.com") != ustring::npos); + /* test obsolete: */ + /* ustring html = m.viewable_text(true); */ + /* BOOST_CHECK (html.find ("line-ignored.com") != ustring::npos); */ teardown (); @@ -86,7 +89,7 @@ BOOST_AUTO_TEST_SUITE(Reading) Message m (fname); - ustring text = m.viewable_text(false, true); + ustring text = m.plain_text (true); BOOST_CHECK (text.find ("line-ignored.com") != ustring::npos); diff --git a/tests/test_non_existant_file.cc b/tests/test_non_existant_file.cc index e5245da..47fbefb 100644 --- a/tests/test_non_existant_file.cc +++ b/tests/test_non_existant_file.cc @@ -72,7 +72,7 @@ BOOST_AUTO_TEST_SUITE(Reading) oos->save_to ("tests/mail/test_mail/wont-work.eml"); LOG (test) << "sender: " << oos->sender; - LOG (test) << "text: " << oos->viewable_text (false); + LOG (test) << "text: " << oos->plain_text (false); /* these do not seem to be cached */ LOG (test) << "to: " << AddressList (oos->to()).str(); |