[evolution] eds-I#13 - [IMAPx] Fails to append message to Yahoo! with no CRLF at the end



commit 20c604da065232f5fe1ea830f8f28391368f140e
Author: Milan Crha <mcrha redhat com>
Date:   Wed Jun 27 17:27:57 2018 +0200

    eds-I#13 - [IMAPx] Fails to append message to Yahoo! with no CRLF at the end
    
    This change makes sure the composer stores message text with CRLF
    at the end. It was possible to save it without it before this change.
    
    Related to https://gitlab.gnome.org/GNOME/evolution-data-server/issues/13

 src/composer/e-msg-composer.c                      | 26 ++++++++++++++++++++--
 src/mail/e-mail-notes.c                            | 25 +++++++++++++++++++--
 .../composer-to-meeting/e-composer-to-meeting.c    |  7 ++++++
 3 files changed, 54 insertions(+), 4 deletions(-)
---
diff --git a/src/composer/e-msg-composer.c b/src/composer/e-msg-composer.c
index 160787cbcd..73bb890069 100644
--- a/src/composer/e-msg-composer.c
+++ b/src/composer/e-msg-composer.c
@@ -1310,6 +1310,8 @@ composer_build_message (EMsgComposer *composer,
                }
 
                g_byte_array_append (data, (guint8 *) text, strlen (text));
+               if (!g_str_has_suffix (text, "\r\n"))
+                       g_byte_array_append (data, (const guint8 *) "\r\n", 2);
                g_free (text);
 
                type = camel_content_type_new ("text", "plain");
@@ -1416,6 +1418,8 @@ composer_build_message (EMsgComposer *composer,
 
                length = strlen (text);
                g_byte_array_append (data, (guint8 *) text, (guint) length);
+               if (!g_str_has_suffix (text, "\r\n"))
+                       g_byte_array_append (data, (const guint8 *) "\r\n", 2);
                pre_encode = text_requires_quoted_printable (text, length);
                g_free (text);
 
@@ -5379,6 +5383,8 @@ e_msg_composer_get_raw_message_text_without_signature (EMsgComposer *composer)
        EHTMLEditor *editor;
        EContentEditor *cnt_editor;
        gchar *content;
+       GByteArray *bytes;
+       gboolean needs_crlf;
 
        g_return_val_if_fail (E_IS_MSG_COMPOSER (composer), NULL);
 
@@ -5397,7 +5403,14 @@ e_msg_composer_get_raw_message_text_without_signature (EMsgComposer *composer)
                content = g_strdup ("");
        }
 
-       return g_byte_array_new_take ((guint8 *) content, strlen (content));
+       needs_crlf = !g_str_has_suffix (content, "\r\n");
+
+       bytes = g_byte_array_new_take ((guint8 *) content, strlen (content));
+
+       if (needs_crlf)
+               g_byte_array_append (bytes, (const guint8 *) "\r\n", 2);
+
+       return bytes;
 }
 
 /**
@@ -5411,6 +5424,8 @@ e_msg_composer_get_raw_message_text (EMsgComposer *composer)
        EHTMLEditor *editor;
        EContentEditor *cnt_editor;
        gchar *content;
+       GByteArray *bytes;
+       gboolean needs_crlf;
 
        g_return_val_if_fail (E_IS_MSG_COMPOSER (composer), NULL);
 
@@ -5428,7 +5443,14 @@ e_msg_composer_get_raw_message_text (EMsgComposer *composer)
                content = g_strdup ("");
        }
 
-       return g_byte_array_new_take ((guint8 *) content, strlen (content));
+       needs_crlf = !g_str_has_suffix (content, "\r\n");
+
+       bytes = g_byte_array_new_take ((guint8 *) content, strlen (content));
+
+       if (needs_crlf)
+               g_byte_array_append (bytes, (const guint8 *) "\r\n", 2);
+
+       return bytes;
 }
 
 gboolean
diff --git a/src/mail/e-mail-notes.c b/src/mail/e-mail-notes.c
index 54aa982e36..b9224bbedb 100644
--- a/src/mail/e-mail-notes.c
+++ b/src/mail/e-mail-notes.c
@@ -343,6 +343,13 @@ e_mail_notes_editor_encode_text_to_message (EMailNotesEditor *notes_editor)
                        NULL, NULL);
 
                if (text && *text) {
+                       if (!g_str_has_suffix (text, "\r\n")) {
+                               gchar *tmp = text;
+
+                               text = g_strconcat (tmp, "\r\n", NULL);
+                               g_free (tmp);
+                       }
+
                        part = camel_mime_part_new ();
                        camel_mime_part_set_content (part, text, strlen (text), "text/plain");
                        camel_multipart_add_part (multipart_alternative, part);
@@ -366,10 +373,17 @@ e_mail_notes_editor_encode_text_to_message (EMailNotesEditor *notes_editor)
                        /* Text is required, thus if there are attachments,
                           but no text, then store at least a space. */
                        g_free (text);
-                       text = g_strdup (" ");
+                       text = g_strdup ("\r\n");
                }
 
                if (text && *text) {
+                       if (!g_str_has_suffix (text, "\r\n")) {
+                               gchar *tmp = text;
+
+                               text = g_strconcat (tmp, "\r\n", NULL);
+                               g_free (tmp);
+                       }
+
                        part = camel_mime_part_new ();
                        camel_mime_part_set_content (part, text, strlen (text), "text/html");
                        camel_multipart_add_part (multipart_alternative, part);
@@ -445,10 +459,17 @@ e_mail_notes_editor_encode_text_to_message (EMailNotesEditor *notes_editor)
                        /* Text is required, thus if there are attachments,
                           but no text, then store at least a space. */
                        g_free (text);
-                       text = g_strdup (" ");
+                       text = g_strdup ("\r\n");
                }
 
                if (text && *text) {
+                       if (!g_str_has_suffix (text, "\r\n")) {
+                               gchar *tmp = text;
+
+                               text = g_strconcat (tmp, "\r\n", NULL);
+                               g_free (tmp);
+                       }
+
                        if (has_attachments) {
                                CamelMultipart *multipart;
                                CamelMimePart *part;
diff --git a/src/modules/composer-to-meeting/e-composer-to-meeting.c 
b/src/modules/composer-to-meeting/e-composer-to-meeting.c
index e13a2cd0d9..5f4c131ac4 100644
--- a/src/modules/composer-to-meeting/e-composer-to-meeting.c
+++ b/src/modules/composer-to-meeting/e-composer-to-meeting.c
@@ -220,6 +220,13 @@ composer_to_meeting_component (EMsgComposer *composer)
                ECalComponentText *description;
                GSList *descr_list = NULL;
 
+               if (!g_str_has_suffix (text, "\r\n")) {
+                       gchar *tmp = text;
+
+                       text = g_strconcat (tmp, "\r\n", NULL);
+                       g_free (tmp);
+               }
+
                description = g_new0 (ECalComponentText, 1);
                description->value = text;
                description->altrep = NULL;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]