commit-mailutils
[Top][All Lists]
Advanced

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

[SCM] GNU Mailutils branch, master, updated. release-3.1.1-36-gfdf27cc


From: Sergey Poznyakoff
Subject: [SCM] GNU Mailutils branch, master, updated. release-3.1.1-36-gfdf27cc
Date: Mon, 16 Jan 2017 11:05:21 +0000 (UTC)

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU Mailutils".

http://git.savannah.gnu.org/cgit/mailutils.git/commit/?id=fdf27cc40bc54494c89e86da5dfdce8b0248f2d3

The branch, master has been updated
       via  fdf27cc40bc54494c89e86da5dfdce8b0248f2d3 (commit)
      from  57c987c11677924928716730abdd68c3d75ea044 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit fdf27cc40bc54494c89e86da5dfdce8b0248f2d3
Author: Sergey Poznyakoff <address@hidden>
Date:   Mon Jan 16 13:00:20 2017 +0200

    Improve mu_attachment_copy_ interface
    
    * libmailutils/mime/attachment.c (mu_attachment_copy_from_stream)
    (mu_attachment_copy_from_file): Remove the encoding parameter.  Take
    the encoding to use from the value of the Content-Transfer-Encoding
    header.  Return EINVAL if it is not present.
    * include/mailutils/message.h (mu_attachment_copy_from_stream)
    (mu_attachment_copy_from_file): Change signature.  All uses changed.

-----------------------------------------------------------------------

Summary of changes:
 include/mailutils/message.h    |    6 ++---
 libmailutils/mime/attachment.c |   57 +++++++++++++++++++++++++---------------
 mail/send.c                    |    2 +-
 3 files changed, 39 insertions(+), 26 deletions(-)

diff --git a/include/mailutils/message.h b/include/mailutils/message.h
index 7abf954..6f8fb6b 100644
--- a/include/mailutils/message.h
+++ b/include/mailutils/message.h
@@ -216,11 +216,9 @@ extern int mu_attachment_create (mu_message_t *newmsg,
                                 const char *encoding,
                                 const char *name, const char *filename);
 extern int mu_attachment_copy_from_stream (mu_message_t att,
-                                          mu_stream_t stream,
-                                          char const *encoding);
+                                          mu_stream_t stream);
 extern int mu_attachment_copy_from_file (mu_message_t att,
-                                        char const *filename,
-                                        char const *encoding);
+                                        char const *filename);
 extern int mu_message_create_attachment (const char *content_type,
                                         const char *encoding,
                                         const char *filename,
diff --git a/libmailutils/mime/attachment.c b/libmailutils/mime/attachment.c
index 6a1d491..50c9289 100644
--- a/libmailutils/mime/attachment.c
+++ b/libmailutils/mime/attachment.c
@@ -108,7 +108,8 @@ at_hdr (mu_header_t hdr, const char *content_type, const 
char *encoding,
     rc = mu_header_append (hdr, MU_HEADER_CONTENT_DISPOSITION, "attachment");
   if (rc)
     return rc;
-  return mu_header_append (hdr, MU_HEADER_CONTENT_TRANSFER_ENCODING, encoding);
+  return mu_header_append (hdr, MU_HEADER_CONTENT_TRANSFER_ENCODING,
+                          encoding ? encoding : "8bit");
 }
 
 /* Create in *NEWMSG an empty attachment of given CONTENT_TYPE and ENCODING.
@@ -149,42 +150,58 @@ mu_attachment_create (mu_message_t *newmsg,
 
 /* ATT is an attachment created by a previous call to mu_attachment_create().
 
-   Fills in the attachment body with the data from STREAM using the specified
-   ENCODING.
+   Fills in the attachment body with the data from STREAM using the encoding
+   stored in the Content-Transfer-Encoding header of ATT.
  */
 int
-mu_attachment_copy_from_stream (mu_message_t att, mu_stream_t stream,
-                               char const *encoding)
+mu_attachment_copy_from_stream (mu_message_t att, mu_stream_t stream)
 {
   mu_body_t body;
   mu_stream_t bstr;
   mu_stream_t tstream;
+  mu_header_t hdr;
   int rc;
+  char *encoding;
+  
+  mu_message_get_header (att, &hdr);
+  rc = mu_header_aget_value_unfold (hdr, MU_HEADER_CONTENT_TRANSFER_ENCODING,
+                                   &encoding);
+  switch (rc)
+    {
+    case 0:
+      break;
+      
+    case MU_ERR_NOENT:
+      return EINVAL;
+
+    default:
+      return rc;
+    }
   
   mu_message_get_body (att, &body);
   rc = mu_body_get_streamref (body, &bstr);
-  if (rc)
-    return rc;
-  
-  rc = mu_filter_create (&tstream, stream, encoding, MU_FILTER_ENCODE,
-                        MU_STREAM_READ);
   if (rc == 0)
     {
-      rc = mu_stream_copy (bstr, tstream, 0, NULL);
-      mu_stream_unref (tstream);
+      rc = mu_filter_create (&tstream, stream, encoding, MU_FILTER_ENCODE,
+                            MU_STREAM_READ);
+      if (rc == 0)
+       {
+         rc = mu_stream_copy (bstr, tstream, 0, NULL);
+         mu_stream_unref (tstream);
+       }
+      mu_stream_unref (bstr);
     }
-  mu_stream_unref (bstr);
+  free (encoding);
   return rc;
 }
 
 /* ATT is an attachment created by a previous call to mu_attachment_create().
 
-   Fills in the attachment body with the data from FILENAME using the specified
-   ENCODING.
+   Fills in the attachment body with the data from FILENAME using the encoding
+   specified in the Content-Transfer-Encoding header.
  */
 int
-mu_attachment_copy_from_file (mu_message_t att, char const *filename,
-                             char const *encoding)
+mu_attachment_copy_from_file (mu_message_t att, char const *filename)
 {
   mu_stream_t stream;
   int rc;
@@ -192,7 +209,7 @@ mu_attachment_copy_from_file (mu_message_t att, char const 
*filename,
   rc = mu_file_stream_create (&stream, filename, MU_STREAM_READ);
   if (rc == 0)
     {
-      rc = mu_attachment_copy_from_stream (att, stream, encoding);
+      rc = mu_attachment_copy_from_stream (att, stream);
       mu_stream_unref (stream);
     }
   return rc;
@@ -208,8 +225,6 @@ mu_message_create_attachment (const char *content_type, 
const char *encoding,
   
   if (content_type == NULL)
     content_type = "text/plain";
-  if (encoding == NULL)
-    encoding = "7bit";
 
   name = strrchr (filename, '/');
   if (name)
@@ -220,7 +235,7 @@ mu_message_create_attachment (const char *content_type, 
const char *encoding,
   rc = mu_attachment_create (&att, content_type, encoding, name, filename);
   if (rc == 0)
     {
-      rc = mu_attachment_copy_from_file (att, filename, encoding);
+      rc = mu_attachment_copy_from_file (att, filename);
       if (rc)
        mu_message_destroy (&att, NULL);
     }
diff --git a/mail/send.c b/mail/send.c
index c369626..22c238c 100644
--- a/mail/send.c
+++ b/mail/send.c
@@ -362,7 +362,7 @@ saveatt (void *item, void *data)
       return 1;
     }
 
-  rc = mu_attachment_copy_from_stream (part, aptr->source, aptr->encoding);
+  rc = mu_attachment_copy_from_stream (part, aptr->source);
   if (rc)
     {
       mu_error (_("cannot attach %s: %s"), aptr->id, mu_strerror (rc));


hooks/post-receive
-- 
GNU Mailutils



reply via email to

[Prev in Thread] Current Thread [Next in Thread]