Re: line breaks in text attachments

"Stanislaw T. Findeisen" <[email protected]> Sat, 10 Nov 2007 12:31:47 +0100
Newsgroups gmane.mail.libetpan.user
Message-ID <[email protected]>
Thanks it works now!

DINH Viêt Hoà wrote:
> On 11/10/07, Stanislaw T. Findeisen <[email protected]> wrote:
>> Hello
>>
>> I am experiencing problems with line breaks in text attachments. I wrote
>> a sample program to demonstrate this problem:
>>
>> =========================================================
>> /**
>>   * Based on compose-msg.c
>>   */
>>
>> #include <stdlib.h>
>> #include <string.h>
>>
>> #include <libetpan/libetpan.h>
>>
>> struct mailimf_fields * build_fields() {
>>      const char * subject            = "line breaks";
>>
>>      struct mailimf_mailbox_list * from = mailimf_mailbox_list_new_empty();
>>      struct mailimf_address_list * to = mailimf_address_list_new_empty();
>>
>>      mailimf_mailbox_list_add_parse(from, "DINH Viet Hoa
>> <[email protected]>");
>>      mailimf_address_list_add_parse(to, "Paul <claws-0/[email protected]>");
>>
>>      struct mailimf_fields * new_fields = mailimf_fields_new_with_data(from,
>>          NULL, NULL, to, NULL, NULL, NULL, NULL, strdup(subject));
>>      return new_fields;
>> }
>>
>> int main(int argc, char ** argv) {
>>      const char * attachmentFilename = "file-1.txt";
>>      const char * sampleText1        = "ab\ncd";
>>      const char * sampleText1Charset = "iso-8859-1";
>>      const int    sampleText1Length  = strlen(sampleText1);
>>
>>      printf("Sample text length is: %d\n", sampleText1Length);
>>      printf("Sample text is: %s\n", sampleText1);
>>
>>      // start the message
>>      struct mailimf_fields * fields = build_fields();
>>      struct mailmime * message = mailmime_new_message_data(NULL);
>>      mailmime_set_imf_fields(message, fields);
>>
>>      // build attachment
>>      struct mailmime_fields * mime_fields =
>> mailmime_fields_new_filename(MAILMIME_DISPOSITION_TYPE_ATTACHMENT,
>> strdup(attachmentFilename), MAILMIME_MECHANISM_QUOTED_PRINTABLE);
>>      struct mailmime_content * mime_content =
>> mailmime_content_new_with_str("text/plain");
>>      struct mailmime_parameter * mime_param =
>> mailmime_param_new_with_data("charset", strdup(sampleText1Charset));
>>      clist_append(mime_content->ct_parameters, mime_param);
>>
>>      struct mailmime * mime_sub = mailmime_new_empty(mime_content,
>> mime_fields);
>>      mailmime_set_body_text(mime_sub, strdup(sampleText1),
>> sampleText1Length);
>>
>>      // add attachment to the message
>>      mailmime_smart_add_part(message, mime_sub);
>>
>>      // write the message out
>>      printf("==== Printing the message:\n\n");
>>      int col = 0;
>>      mailmime_write(stdout, &col, message);
>>      mailmime_free(message);
>>      printf("#DONE\n");
>>
>>      return 0;
>> }
>> =========================================================
>>
>> The output of this program on my computer is:
>>
>> =========================================================
>> Sample text length is: 5
>> Sample text is: ab
>> cd
>> ==== Printing the message:
>>
>> Date: Sat, 10 Nov 2007 10:57:56 +0100
>> From: DINH Viet Hoa <[email protected]>
>> To: Paul <claws-0/[email protected]>
>> Message-ID: <etPan.473580a4.6b8b4567.2ecb@thinkpad>
>> Subject: line breaks
>> MIME-Version: 1.0
>> Content-Type: text/plain; charset="iso-8859-1"
>> Content-Transfer-Encoding: quoted-printable
>> Content-Disposition: attachment; filename="file-1.txt"
>>
>> ab
>> #DONE
>> =========================================================
>>
>> It seems that the last line is cut out.
>>
>> When using "sample text\nwith\nseveral\nlines." as a sample text, the
>> last line is being cut also.
>>
>> With different encodings like utf-8 the problem was the same.
>>
>> Am I doing anything wrong, or is this a bug?
> 
> Hello,
> 
> This is obviously a bug.
> I analyzed it and last line was flushed only if there was an ending
> '\n' in the text (in quoted-printable generation).
> You can either update using the CVS or workaround the bug by adding an
> ending '\n'.
> 
> Thanks for reporting,
> 

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/