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

Problem: composing emails when thread_view.preferred_type = html #532

Open
yrashk opened this issue Jul 30, 2018 · 13 comments
Open

Problem: composing emails when thread_view.preferred_type = html #532

yrashk opened this issue Jul 30, 2018 · 13 comments

Comments

@yrashk
Copy link
Contributor

yrashk commented Jul 30, 2018

When thread_view.preferred_type is set to html, composing a plain text email ends up in wiping out message body after exiting from the editor.

When preferred_type is reverted back to plain, everything works as expected, but we lose the ability to see emails in the mailbox as HTML by default.

Here's a test that confirms this:

  BOOST_AUTO_TEST_CASE (compose_test_body_preferred_html)
  {
    using Astroid::ComposeMessage;
    using Astroid::Message;
    setup ();
    const_cast<ptree&>(astroid->config("thread_view")).put ("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.viewable_text (false);

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

    unlink (fn.c_str ());

    teardown ();

  }

This behaviour happens in Chunk where Chunk queries the configuration and if the type is preferred it sets the preferred property on a chunk to true. This, in turn, is used in Message which is in turn used by ComposeMessage. Since no chunk is marked as preferred, none is used.

Proposed solution: if no chunks is found to be preferred, pick one.

P.S. I am trying to produce a patch to fix this, but this might take a bit of time (the fact that I never really used C++ is not helping me!)

@gauteh
Copy link
Member

gauteh commented Jul 30, 2018 via email

@yrashk
Copy link
Contributor Author

yrashk commented Jul 31, 2018

I've checked, viewable_text is also used in src/modes/thread_view

So far, this is the patch that seems to fix the issue:

diff --git a/src/compose_message.cc b/src/compose_message.cc
index b6a1a25..68b45c2 100644
--- a/src/compose_message.cc
+++ b/src/compose_message.cc
@@ -283,7 +283,7 @@ namespace Astroid {
 
     set_subject (msg.subject);
 
-    body << msg.viewable_text (false);
+    body << msg.viewable_text (false, true);
 
   }
 
diff --git a/src/modes/forward_message.cc b/src/modes/forward_message.cc
index a47adc1..ca6a2fc 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->viewable_text(false, true);
       quoted << vt;
 
       body = ustring(quoted.str());
diff --git a/src/modes/reply_message.cc b/src/modes/reply_message.cc
index c3b673d..3221d60 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->viewable_text(false, true);
     stringstream sstr (vt);
     while (sstr.good()) {
       string line;
diff --git a/tests/test_composed_message.cc b/tests/test_composed_message.cc
index e401dd0..9da7932 100644
--- a/tests/test_composed_message.cc
+++ b/tests/test_composed_message.cc
@@ -8,6 +8,7 @@
 # include "account_manager.hh"
 # include "utils/address.hh"
 # include "utils/ustring_utils.hh"
+# include "db.hh"
 
 BOOST_AUTO_TEST_SUITE(Composing)
 
@@ -54,6 +55,38 @@ BOOST_AUTO_TEST_SUITE(Composing)
 
   }
 
+  BOOST_AUTO_TEST_CASE (compose_test_body_preferred_html)
+  {
+    using Astroid::ComposeMessage;
+    using Astroid::Message;
+    setup ();
+    const_cast<ptree&>(astroid->config("thread_view")).put ("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;
+
+    ComposeMessage * m = new ComposeMessage ();
+    m->load_message ("id", fn);
+    ustring rbdy(m->body.str());
+
+    BOOST_CHECK_MESSAGE (bdy == rbdy, "message reading produces the same output as compose message input");
+
+    unlink (fn.c_str ());
+
+    teardown ();
+
+  }
+
   BOOST_AUTO_TEST_CASE (compose_test_references)
   {
     using Astroid::ComposeMessage;

What do you think? I've also confirmed the intended behavior in the application, it does now preserve the plain text of the message and sends it correctly but it does NOT show it in the preview before sending (any clues on how to fix that? I suspect that this is also related to the fact that html is preferred but there's obviously none). Previously, neither preview nor actual sent message contained the authored body.

@gauteh
Copy link
Member

gauteh commented Jul 31, 2018 via email

@gauteh
Copy link
Member

gauteh commented Jul 31, 2018 via email

@yrashk
Copy link
Contributor Author

yrashk commented Jul 31, 2018

I can confirm that your patch works as well, however it still doesn't show the text in the preview pane before sending -- but the body is not lost (it can be seen by re-entering into the editor).

Any thoughts on how we can make the preview work?

@gauteh
Copy link
Member

gauteh commented Jul 31, 2018 via email

@gauteh
Copy link
Member

gauteh commented Jul 31, 2018 via email

@gauteh
Copy link
Member

gauteh commented Aug 8, 2018 via email

@yrashk
Copy link
Contributor Author

yrashk commented Aug 8, 2018 via email

@gauteh
Copy link
Member

gauteh commented Oct 19, 2018 via email

@davvil
Copy link

davvil commented Nov 6, 2018

#545 solves the issue for me.

@gauteh
Copy link
Member

gauteh commented Nov 6, 2018

Thanks, closing for now.

@gauteh gauteh closed this as completed Nov 6, 2018
@gauteh
Copy link
Member

gauteh commented Nov 6, 2018

Hm, noticed that I made some other changes.. needs some work before merge.

@gauteh gauteh reopened this Nov 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants