home *** CD-ROM | disk | FTP | other *** search
/ Big Green CD 8 / BGCD_8_Dev.iso / NEXTSTEP / UNIX / Mail / appnmail-1.8-Solaris / mailapp-utilities / nextmail.m < prev    next >
Encoding:
Text File  |  1997-04-19  |  3.6 KB  |  134 lines

  1. /* -*-C-*-
  2. *******************************************************************************
  3. *
  4. * File:         nextmail.m
  5. * RCS:          /usr/local/sources/CVS/mailapp-utilities/nextmail.m,v 1.3 1997/04/19 17:37:26 tom Exp
  6. * Description:  A 'mail' compatible program to open a Mail.app Compose window
  7. * Author:       Carl Edman
  8. * Created:      Thu Mar  4 13:42:52 1993
  9. * Modified:     Sat Nov 30 23:29:19 1996 Tom Hageman <tom@basil.icce.rug.nl>
  10. * Language:     Objective C
  11. * Package:      mailapp-utilities
  12. * Status:       First release
  13. *
  14. * (C) Copyright 1993, but otherwise this file is perfect freeware.
  15. *
  16. *******************************************************************************
  17. */
  18.  
  19. #import <appkit/appkit.h>
  20. #import <stdlib.h>
  21. #import <stdio.h>
  22. #import "MailSpeaker.h"
  23. #import "mailutil.h"
  24. #import "mailtoc.h"
  25. #import "optutil.h"
  26.  
  27. #define USAGE "\
  28. Usage: %s [-e] [-s subject] [-c user]... [-NXHost host] [-V|-H] [user...]\n"
  29.  
  30. #define HELP "\
  31.  -e           edit message in Compose window (default is to deliver immediately)\n\
  32.  -s subject   set Subject: to `subject'\n\
  33.  -c user      cc: to `user' (allowed multiple times)\n\
  34.  -NXHost host connect to Mail.app on given host\n\
  35.  -V           show version\n\
  36.  -H           this help\n\
  37. "
  38.  
  39. void main(int ac,char *av[])
  40. {
  41.    id         speaker;
  42.    port_t     mailPort;
  43.    int window;
  44.    char *to=0,*subject=0,*cc=0,*content=0;
  45.    int tolen=0,subjectlen=0,cclen=0,contentlen=0;
  46.    int tomaxlen=0,subjectmaxlen=0,ccmaxlen=0,contentmaxlen=0;
  47.    int editflg=0,c,i;
  48.    char *host=NULL;
  49.    int status=EXIT_SUCCESS;
  50.  
  51.    set_progname(av[0]);
  52.  
  53.    while((c=getopt(ac,av,"s:c:eN:VH"))!=EOF) switch(c)
  54.    {
  55.     case 's':
  56.       if (subject) appstring(&subject,&subjectlen,&subjectmaxlen," ",1);
  57.       appstring(&subject,&subjectlen,&subjectmaxlen,optarg,strlen(optarg));
  58.       break;
  59.     case 'c':
  60.       if (cc) appstring(&cc,&cclen,&ccmaxlen,",",1);
  61.       appstring(&cc,&cclen,&ccmaxlen,optarg,strlen(optarg));
  62.     case 'e':
  63.       editflg++;
  64.       break;
  65.     case 'N':
  66.       if ((strcmp(optarg,"XHost")==0||strcmp(optarg,"SHost")==0)&&(optind<ac))
  67.       {
  68.      host=av[optind++];
  69.      break;
  70.       }
  71.       status=EXIT_USAGE;
  72.       break;
  73.     case 'V':
  74.       status=EXIT_VERSION;
  75.       break;
  76.     case 'H':
  77.       status=EXIT_HELP;
  78.       break;
  79.     case '?':
  80.     default:
  81.       status=EXIT_USAGE;
  82.       break;
  83.    }
  84.    handle_usage_help_version(status, USAGE, HELP);
  85.  
  86.    for(;optind<ac;optind++)
  87.    {
  88.       if (to) appstring(&to,&tolen,&tomaxlen,",",1);
  89.       appstring(&to,&tolen,&tomaxlen,av[optind],strlen(av[optind]));
  90.    }
  91.  
  92.    while((i=fread(growstring(&content,&contentlen,&contentmaxlen,LINELEN*16),
  93.                   1,16*LINELEN,stdin))>0)
  94.       contentlen+=i;
  95.  
  96.    speaker = [[MailSpeaker alloc] init];
  97.    mailPort = NXPortFromName("Mail", host);
  98.    mailPort = NXPortFromName("MailSendDemo", host);
  99.  
  100.    if (mailPort == PORT_NULL) 
  101.    {
  102.       fprintf(stderr,"%s: unable to connect to Mail.app on %s\n", progname(), host ? host : "localhost");
  103.       exit(EXIT_FAILURE);
  104.    }
  105.    
  106.    [speaker setSendPort: mailPort];
  107.    [speaker openSend:&window];
  108.    if (to)
  109.    {
  110.       appstring(&to,&tolen,&tomaxlen,"\0",1);
  111.       [speaker setTo:to inWindow:window];
  112.    }
  113.    if (subject)
  114.    {
  115.       appstring(&subject,&subjectlen,&subjectmaxlen,"\0",1);
  116.       [speaker setSubject:subject inWindow:window];
  117.    }
  118.    if (cc)
  119.    {
  120.       appstring(&cc,&cclen,&ccmaxlen,"\0",1);
  121.       [speaker setCc:cc inWindow:window];
  122.    }
  123.    if (content)
  124.    {
  125.       appstring(&content,&contentlen,&contentmaxlen,"\0",1);
  126.       [speaker setBody:content inWindow:window];
  127.    }
  128.    if ((!editflg) && to) [speaker deliver:window];
  129.    
  130.    [speaker free];
  131.  
  132.    exit(EXIT_SUCCESS);
  133. }
  134.