home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Mail / MailEnclosure / MESendModules / Source / MIME / MIMEMail.m < prev    next >
Encoding:
Text File  |  1995-06-12  |  1.4 KB  |  60 lines

  1. #import "MIMEMail.h"
  2. #import "FileName.h"
  3. #import "support.h"
  4. #include <sys/file.h>
  5.  
  6. #define MIME_VERSION "MIME-Version: 1.0\n"
  7. #define MAJOR_CONTENT_TYPE "Content-Type: multipart/mixed; boundary="
  8. #define TEXT_CONTENT_TYPE "Content-Type: TEXT/plain; CHARSET=US-ASCII\n"
  9. #define SUB_CONTENT_TYPE "Content-Type: APPLICATION/octet-stream; name =\"%s\"\nContent-Transfer-Encoding: BASE64\n\n"
  10. #define BOUNDRY "\n--MailEnclosure-Boundry--------MailEnclosure-Boundry"
  11.  
  12. @implementation MIMEMail
  13.  
  14. - buildEnvelope
  15. {
  16.    [super buildEnvelope];
  17.    fwrite(MIME_VERSION, 1, strlen(MIME_VERSION), fp);
  18.    fwrite(MAJOR_CONTENT_TYPE, 1, strlen(MAJOR_CONTENT_TYPE), fp);
  19.    putc('"',fp);
  20.    fwrite(BOUNDRY + 3, 1, strlen(BOUNDRY + 3), fp);
  21.    putc('"',fp);
  22.    putc('\n',fp);
  23.    return self;
  24. }
  25.  
  26. - buildBody
  27. {
  28.    id aFile;
  29.    int cnt, x;
  30.    int blen = strlen(BOUNDRY);
  31.  
  32.    if(strlen([text stringValue]))
  33.    {
  34.       fwrite(BOUNDRY,1,blen,fp);
  35.       putc('\n',fp);
  36.       fwrite(TEXT_CONTENT_TYPE,1,strlen(TEXT_CONTENT_TYPE),fp);
  37.       fwrite([text stringValue], 1, strlen([text stringValue]),fp);
  38.    }
  39.    
  40.    for(x = 0, cnt = [attachments count]; x < cnt; x++)
  41.    {
  42.       aFile = [attachments objectAt: x];
  43.       fwrite(BOUNDRY,1,blen,fp);
  44.       putc('\n',fp);
  45.       fprintf(fp,SUB_CONTENT_TYPE, [aFile basename]);
  46.       base64([aFile stringValue], fp);
  47.    }
  48.    
  49.    fwrite(BOUNDRY,1,blen,fp);
  50.    fwrite("--\n",1,3,fp);
  51.    return self;
  52. }
  53.  
  54. + (BOOL)supportsAttachments
  55. {
  56.    return YES;
  57. }
  58.  
  59. @end
  60.