ftp.nice.ch/pub/next/connectivity/mail/apps/MailEnclosure.0.15.NIHS.bs.tar.gz#/MailEnclosure/Source.v0.15/MailMessage.m

This is MailMessage.m in view mode; [Download] [Up]

#import "MailMessage.h"
#import "EnhancedText.h"
#import "TokenString.h"
#import "MasterController.h"
#import "Defaults.h"
#import <stdio.h>

@implementation MailMessage

-initForMUA: (const char *)anApp  andMTA: (const char *)aMailer
{
   [super init];
   MUA = [[StringStorage alloc] init: anApp];
   MTA = [[StringStorage alloc] init: aMailer];
   to = [[StringStorage alloc] init];
   subject = [[StringStorage alloc] init];
   cc  = [[StringStorage alloc] init];
   text  = [[StringStorage alloc] init];
   mailFile  = [[StringStorage alloc] init];
   envelope  = [[StringStorage alloc] init];
   body = [[StringStorage alloc] init];
   commandLine = [[StringStorage alloc] init];

   [commandLine appendStringValue: [MTA stringValue]];
   [commandLine appendCharValue: ' '];
   fp = (FILE *)0;
   return self;
}

-free
{
   [MUA free];
   [MTA free];
   [to free];
   [subject free];
   [cc free];
   [text free];
   [mailFile free];
   [envelope free];
   [body free];
   [commandLine free];
   return [super free];
}

-commandArgs
{
   const char *str;
   id tokens = [[TokenString alloc] init: [to stringValue]];

   [tokens setSeparator: ','];
   
   while(str = [tokens popStringValue])
   {
      [commandLine appendStringValue: str];
      [commandLine appendCharValue:' '];
   }
   
   str = [cc stringValue];
   if(str && *str)
   {
      [tokens setStringValue: str];
      while(str = [tokens popStringValue])
      {
	 [commandLine appendStringValue: str];
	 [commandLine appendCharValue:' '];
      }
   }
   [tokens free];
   return self;
}

-buildEnvelope
{
   const char *str;

   [envelope appendStringValue: "Received: by \001\nTo: \002\nSubject: \003\n"];
   [envelope replaceSubstring: "\001" with: [MUA stringValue]];       
   [envelope replaceSubstring: "\002" with: [to stringValue]];
   [envelope replaceSubstring: "\003" with: [subject stringValue]];

					     /* cc: */
   str = [cc stringValue];
   if(str && *str)
   {
      [envelope appendStringValue: "CC: %s\n"];
      [envelope replaceSubstring: "%s" with: str];
   }

   str = [[[NXApp delegate] defaults] get: "ReplyTo"];
   if(str && *str)
   {
      [envelope appendStringValue: "Reply-To: %s\n"];
      [envelope replaceSubstring: "%s" with: str];
   }

   if(*[mailFile stringValue] && fp)   /* generating a file - not memory image */
       fwrite([envelope stringValue], 1, [envelope strlen], fp);
   
   return self;
}

-buildBody
{
   [body setStringValue: "\n"];
   [body appendStringValue: [text stringValue]];
   return self;
}

-deliverTo: (const char *)receivers
   subject: (const char *)about
        cc: (const char *)alsoReceives 
      text: (const char *)str
{
   [to setStringValue: receivers];
   [subject setStringValue: about];
   [cc setStringValue: alsoReceives];
   [text setStringValue: str];
   [self commandArgs];
   [self buildEnvelope];
   [self buildBody];

   if(*[mailFile stringValue] && fp)   /* generated a file - not memory image */
   {
      fflush(fp);
      [commandLine appendStringValue: " < "];
      [commandLine appendStringValue: [mailFile stringValue]];
      system([commandLine stringValue]);
   }
   else
   {
      FILE *cmd;

      cmd = popen([commandLine stringValue], "w");
      if(!cmd)
      {
	 NXLogError("command failed: %s", [commandLine stringValue]);
	 return nil;
      }
   
      fputs([envelope stringValue], cmd);
      fputs([body stringValue], cmd);
      pclose(cmd);
   }
   
   return self;
}


+ (BOOL)supportsAttachments
{
   return NO;
}

- setAttachments: fileList
{
   attachments = fileList;
   return self;
}


@end

These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.