Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preferred html always #545

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 6 additions & 2 deletions src/chunk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,10 @@ namespace Astroid {

}

bool Chunk::is_content_type (const char * major, const char * minor) {
return (mime_object != NULL) && g_mime_content_type_is_type (content_type, major, minor);
}

ustring Chunk::viewable_text (bool html = true, bool verbose) {
if (isencrypted && !crypt->decrypted) {
if (verbose) {
Expand All @@ -258,7 +262,7 @@ namespace Astroid {
LOG (debug) << "chunk: body: part";


if (g_mime_content_type_is_type (content_type, "text", "plain")) {
if (is_content_type ("text", "plain")) {
LOG (debug) << "chunk: plain text (out html: " << html << ")";

GMimeDataWrapper * content = g_mime_part_get_content (
Expand Down Expand Up @@ -328,7 +332,7 @@ namespace Astroid {

content_stream = filter_stream;

} else if (g_mime_content_type_is_type (content_type, "text", "html")) {
} else if (is_content_type ("text", "html")) {
LOG (debug) << "chunk: html text";

GMimeDataWrapper * content = g_mime_part_get_content (
Expand Down
1 change: 1 addition & 0 deletions src/chunk.hh
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ namespace Astroid {
ustring content_id;

ustring get_content_type ();
bool is_content_type (const char* major, const char* minor);

ustring viewable_text (bool, bool verbose = false);

Expand Down
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->preferred) {
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 (),
[](refptr<Chunk> c) { return (!c->preferred); })) {
[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->preferred || html || 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
37 changes: 35 additions & 2 deletions tests/test_composed_message.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
# include "account_manager.hh"
# include "utils/address.hh"
# include "utils/ustring_utils.hh"
# include <boost/property_tree/ptree.hpp>

BOOST_AUTO_TEST_SUITE(Composing)

Expand Down Expand Up @@ -44,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 @@ -142,13 +143,45 @@ 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 ());
}

teardown ();
}

BOOST_AUTO_TEST_CASE (compose_test_body_preferred_html)
{
using Astroid::ComposeMessage;
using Astroid::Message;
using boost::property_tree::ptree;

setup ();
const_cast<ptree&>(astroid->config()).put ("thread_view.preferred_type", "html");

ComposeMessage * c = new ComposeMessage ();

ustring bdy = "This is test: æøå.\n > testing\ntesting\n...";

LOG (trace) << "cm: writing utf-8 text to message body: " << bdy;
c->body << bdy;

c->build ();
c->finalize ();
ustring fn = c->write_tmp ();

delete c;

Message m (fn);

ustring rbdy = m.plain_text (false);

BOOST_CHECK_MESSAGE (bdy == rbdy, "message reading produces the same output as compose message input");

unlink (fn.c_str ());
teardown ();
}

BOOST_AUTO_TEST_SUITE_END()

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