[geary/wip/362-utf8-attachments: 6/8] Don't bother checking for best encoding for non-text parts



commit d93ab3594c339a9a444db3fda639918a09c382e9
Author: Michael Gratton <mike vee net>
Date:   Fri Jul 19 20:49:55 2019 +1000

    Don't bother checking for best encoding for non-text parts
    
    Most non text/* files will need to be Base64 encoded, so just assume
    that by defaut.

 src/engine/rfc822/rfc822-message.vala | 37 +++++++++++++++++++++++------------
 1 file changed, 25 insertions(+), 12 deletions(-)
---
diff --git a/src/engine/rfc822/rfc822-message.vala b/src/engine/rfc822/rfc822-message.vala
index 6b335bd5..c530ea88 100644
--- a/src/engine/rfc822/rfc822-message.vala
+++ b/src/engine/rfc822/rfc822-message.vala
@@ -436,25 +436,38 @@ public class Geary.RFC822.Message : BaseObject, EmailHeaderSet {
         GMime.Part part = new GMime.Part();
         part.set_disposition(disposition.serialize());
         part.set_filename(file.get_basename());
-        part.set_content_type(
-            new GMime.ContentType.from_string(file_info.get_content_type())
+
+        GMime.ContentType content_type = new GMime.ContentType.from_string(
+            file_info.get_content_type()
         );
+        part.set_content_type(content_type);
 
-        // This encoding is the initial encoding of the stream.
         GMime.StreamGIO stream = new GMime.StreamGIO(file);
         stream.set_owner(false);
-        part.set_content_object(
-            new GMime.DataWrapper.with_stream(
-                stream, GMime.ContentEncoding.BINARY
-            )
-        );
-        part.set_content_encoding(
-            yield Utils.get_best_encoding(
+
+        // Text parts should be scanned fully to determine best
+        // (i.e. most compact) transport encoding to use, but
+        // that's usually fine since they tend to be
+        // small. Non-text parts are nearly always going to be
+        // binary, so we just assume they require Base64.
+        //
+        // XXX We should be setting the content encoding lazily
+        // though because if sending via a MTA that supports 8-bit
+        // or binary transfer modes, we can avoid using a content
+        // encoding altogether.
+        GMime.ContentEncoding encoding = BASE64;
+        if (content_type.is_type("text", Mime.ContentType.WILDCARD)) {
+            encoding = yield Utils.get_best_encoding(
                 stream,
-                // Determine this from the MTA's capabilities at send
-                // time
                 GMime.EncodingConstraint.7BIT,
                 cancellable
+            );
+        }
+
+        part.set_content_encoding(encoding);
+        part.set_content_object(
+            new GMime.DataWrapper.with_stream(
+                stream, GMime.ContentEncoding.BINARY
             )
         );
         return part;


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