List Info

Thread: Sending MIME Mails




Sending MIME Mails
country flaguser name
Germany
2007-08-24 17:08:01
Hi all,

I used to send MIME mails with attachments as follows:

#define SENDMAIL "/usr/lib/sendmail -t"

+ (void)sendMailFrom:(NSString *)from to:(NSString *)to 
subject:(NSString *)subject body:(NSString *)body
attachments:(NSArray 
*)attachments
{
    FILE *out = popen(SENDMAIL, "w");
    fprintf(out, "From: %sn", [from cString]);
    fprintf(out, "To: %sn", [to cString]);
    fprintf(out, "Subject: %sn", [subject
cString]);

    if ([attachments count]) // MIME message
      {
       NSEnumerator *enumerator = [attachments
objectEnumerator];
       NSDictionary *dic;
       NSString *mime_boundary = 
"-1747901728-1448367683-913849620=:4553";

       fprintf(out, "MIME-Version: 1.0n");
       fprintf(out, "Content-Type: multipart/mixed;
BOUNDARY="%s"n", 
[mime_boundary cString]);
       fprintf(out, "n");

       // write dummy message body
       fprintf(out,"  This message is in MIME format. 
The first part 
should be readable text,n");
       fprintf(out,"  while the remaining parts are
likely unreadable 
without MIME-aware tools.n");
       fprintf(out,"  Send mail to mimedocserver.cac.washington.edu for 
more info.n");
       fprintf(out,"n");

       // write message text
       fprintf(out, "--%sn", [mime_boundary
cString]);
       fprintf(out, "Content-Type: text/plain;
charset=US-ASCIIn");
       fprintf(out,"n");
       fprintf(out, [body cString]);
       fprintf(out,"n");

       while (dic = [enumerator nextObject])
         {
          NSString *filename = [dic objectForKey:"filename"];
          NSData *data = [dic objectForKey:"data"];
          NSData *encodedData = [GSMimeDocument
encodeBase64:data];

          fprintf(out,"--%sn", [mime_boundary
cString]);
          fprintf(out,"Content-Type: %s;
name="%s"n", [[self 
guessMIMEType:filename] cString], [[self basename:filename]
cString]);
          fprintf(out,"Content-Transfer-Encoding:
base64n");
          fprintf(out,"Content-Description:n");
          fprintf(out,"n");

          // mime kodierte Daten des attachments ausgeben
          if (encodedData)
            {
             int i, length = [encodedData length];
             const char *pChar = [encodedData bytes];
             for (i = 0 ; i < length ; i++)
               {
                putc(*pChar, out);
                pChar++;
               }
             fprintf(out,"rn");
            }
         }

       fprintf(out, "--%s--n", [mime_boundary
cString]);
      }
    else
      {
       fprintf(out, "n");
       fprintf(out, [body cString]);
      }
    pclose(out);
}

If I remember correctly this worked with an older version of
GNUstep 
(but I could also be wrong here). I just tried that with the
latest 
GNUstep release. The mail is sent (of course) but the
attachment does 
not get through correctly. PDF or TIFFs or whatever cannot
be opened on 
the other end. It seems that Mail.app does not do the back
conversion 
from base64 to binary format. What am I missing?

Thanks a lot!

Regards,

   Andreas



_______________________________________________
Discuss-gnustep mailing list
Discuss-gnustepgnu.org
http://lists.gnu.org/mailman/listinfo/discuss-gnustep

Re: Sending MIME Mails
country flaguser name
Germany
2007-08-25 17:17:04
On 25.08.2007, at 00:08, Andreas Höschler wrote:
>       fprintf(out,"n");

Shouldn't the 'n's be 'rn's? If I'm not mistaken n will
probably  
result in wrapped headers?

Helge
-- 
Helge Hess
http://www.helgehess.eu/





_______________________________________________
Discuss-gnustep mailing list
Discuss-gnustepgnu.org
http://lists.gnu.org/mailman/listinfo/discuss-gnustep

[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )