Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
message: move viewable_text to plain_text
  • Loading branch information
gauteh committed Oct 19, 2018
commit 2899dd845a653b76f5bb4b40068caee2624032fe
3 changes: 1 addition & 2 deletions src/compose_message.cc
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,7 @@ namespace Astroid {

set_subject (msg.subject);

body << msg.viewable_text (false);

body << msg.plain_text (false);
}

void ComposeMessage::finalize () {
Expand Down
20 changes: 6 additions & 14 deletions src/message_thread.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand All @@ -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;
Expand All @@ -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(),
Expand Down
4 changes: 2 additions & 2 deletions src/message_thread.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion src/modes/forward_message.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion src/modes/reply_message.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/modes/thread_view/page_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) + "...";

Expand Down
6 changes: 3 additions & 3 deletions src/modes/thread_view/thread_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions tests/test_bad_content_id.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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]; */
Expand Down Expand Up @@ -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]; */
Expand Down
6 changes: 3 additions & 3 deletions tests/test_composed_message.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down Expand Up @@ -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 ());
}
Expand Down Expand Up @@ -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");

Expand Down
4 changes: 2 additions & 2 deletions tests/test_convert_error.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 ();
}
Expand All @@ -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;
Expand Down
10 changes: 5 additions & 5 deletions tests/test_crypto.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down Expand Up @@ -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");

Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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++;
}
Expand Down Expand Up @@ -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");

Expand Down
2 changes: 1 addition & 1 deletion tests/test_markdown.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
2 changes: 1 addition & 1 deletion tests/test_mime_message.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 ();
}
Expand Down
23 changes: 13 additions & 10 deletions tests/test_no_newline_msg.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 ();
}
Expand All @@ -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 ();
Expand All @@ -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 ();
Expand All @@ -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);


Expand Down
2 changes: 1 addition & 1 deletion tests/test_non_existant_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down