1: #include "parms.h"
   2: #include "structs.h"
   3: 
   4: #ifdef  RCSIDENT
   5: static char rcsid[] = "$Header: mailit.c,v 1.7.0.3 85/07/25 14:07:21 notes Rel $";
   6: #endif	RCSIDENT
   7: 
   8: /*
   9:  *	mailit
  10:  *
  11:  *	takes the text record specified, along with the notefile name,
  12:  *	the author name, (other things added later), and builds a
  13:  *	temp file. The user is prompted for a list of the people to
  14:  *	send the file to. After an edit session, the mail is sent.
  15:  *
  16:  *	Returns:	-1 if no letter sent
  17:  *			 0 if letter sent (or if it thinks so)
  18:  *
  19:  *	Original author: Ray Essick	June 1981.
  20:  *	modified:	Ray Essick	December 1981.
  21:  *	modified again:	Thanks to Malcolm Slaney of Purdue EE dept.
  22:  *		added the SUPERMAILER processing. May 25, 1982
  23:  *
  24:  */
  25: 
  26: mailit (io, where, author, date, title, toauth, wtext)
  27: struct io_f *io;
  28: struct daddr_f *where;
  29: struct auth_f  *author;
  30: struct when_f  *date;
  31: char   *title;
  32: /* toauth - true if mail to author of note */
  33: /* wtext - true is mail with text of note */
  34: {
  35:     char    buf[128];                   /* > 5 + 80 + 3 + 15 */
  36:     char    whoto[WDLEN + 1];               /* destination */
  37:     char   *command;                    /* mailer to use */
  38:     char    fn[20];                 /* hold scratch file name */
  39:     int     f;
  40:     char   *p;
  41: #ifdef  SUPERMAILER
  42:     char    subject[TITLEN + 20];           /* subject line for super mailer */
  43: #endif
  44:     int     i;
  45:     FILE * txtfile;
  46: 
  47:     if (toauth)
  48:     {
  49:     if (strcmp (author -> aname, "Anonymous") == 0)
  50:     {
  51:         printf ("Can't send to Anonymous\n");
  52:         fflush (stdout);
  53:         sleep (2);
  54:         return (-1);
  55:     }
  56:     }
  57: 
  58:     if (toauth)
  59:     {
  60:     if (strcmp (System, author -> asystem) != 0)
  61:     {
  62: #ifdef  USERHOST
  63:         sprintf (whoto, "%s@%s", author -> aname, author -> asystem);
  64: #else
  65:         sprintf (whoto, "%s!%s", author -> asystem, author -> aname);
  66: #endif	USERHOST
  67:     }
  68:     else
  69:         sprintf (whoto, "%s", author -> aname);
  70:     }
  71:     else
  72:     {
  73:     at (0, 1);
  74:     printf ("\nSend to whom? ");
  75:     if (gline (whoto, WDLEN) == 1)          /* will flush stdout */
  76:         return (-1);                /* no letter sent */
  77: 
  78:     }
  79: 
  80: #ifdef  SUPERMAILER
  81:     strcpy (subject, title);
  82:     for (p = subject; *p; p++)
  83:     if (*p == '"' || *p == '`')
  84:         *p = '\'';                  /* eliminate escape troubles */
  85: #endif	SUPERMAILER
  86: 
  87:     sprintf (fn, "/tmp/nfm%d", getpid ());
  88:     x ((txtfile = fopen (fn, "w")) == NULL, "mailit: creat tmp");
  89:     x (chmod (fn, 0666) < 0, "mailit: chmod tmp");
  90: 
  91:     if (wtext)                      /* add text if specified */
  92:     {
  93:     preptxt (io, txtfile, author, date, where, title);
  94:     }
  95: 
  96:     fclose (txtfile);
  97: 
  98:     if ((command = getenv ("MAILER")) == NULL)      /* override it? */
  99:     command = MAILER;               /* use default */
 100:     at (0, 1);
 101: #ifdef  SUPERMAILER                 /* dumb mail interface */
 102:     if (wtext)                      /* do it hard way if with text */
 103:     {
 104: #endif
 105:     printf ("Edit letter:\n");
 106:     fflush (stdout);                /* clean out buffer */
 107: #ifndef FASTFORK
 108:     sprintf (buf, "%s %s", hised, fn);      /* build edit command */
 109:     dounix (buf, 1, 1);             /* call editor */
 110: #else
 111:     dounix (1, 1, hised, fn, 0, 0, 0);
 112: #endif
 113: 
 114: 
 115:     f = 0;                      /* assume normal termination */
 116:     while (1)
 117:     {
 118:         sprintf (buf, "Send this to %s? (y/n):", whoto);
 119:         fflush (stdout);
 120:         if (askyn (buf) == 'y')
 121:         {
 122:         printf ("\nSending...\n");
 123:         fflush (stdout);
 124: #ifdef SUPERMAILER
 125:         sprintf (buf, "%s -s \"%s\" %s < %s", command, subject, whoto, fn);
 126: #else
 127:         sprintf (buf, "%s %s < %s", command, whoto, fn);
 128: #endif
 129:                             /* make the command */
 130: #ifndef FASTFORK
 131:         f = dounix (buf, 1, 0);         /* mail the thing */
 132: #else
 133:         f = dounix (1, 0, DFLTSH, "-c", buf, 0, 0);
 134: /*
 135:  *	Can't let him use the C shell, since we don't escape the '!' in
 136:  *	remote addresses. RBE 6/21/82
 137:  */
 138: #endif
 139:         break;                  /* out of loop */
 140:         }
 141:         else                    /* not to him... */
 142:         {
 143:         /*
 144: 		 * let him pick a new addressee
 145: 		 */
 146:         printf ("\nSend to whom? ");
 147:         if (gline (whoto, WDLEN) == 1)      /* will flush stdout */
 148:             break;              /* don't send */
 149: 
 150:         }
 151:     }
 152: #ifdef  SUPERMAILER                 /* simple case for SUPERMAILER */
 153:     }
 154:     else
 155:     {
 156:     printf ("%s %s\n", command, whoto);
 157:     fflush (stdout);                /* empty buffers */
 158:     sprintf (buf, "%s %s", command, whoto);
 159: #ifndef FASTFORK
 160:     f = dounix (buf, 1, 1);             /* set the uid & tty */
 161: #else
 162:     f = dounix (1, 1, DFLTSH, "-c", buf, 0, 0); /* do it */
 163: #endif	FASTFORK
 164:     }
 165: #endif	SUPERMAILER
 166: 
 167: #ifdef  SUPERMAILER
 168:     if (f != 0)                     /* pause for error message */
 169:     {
 170:     fflush (stdout);
 171:     sleep (2);
 172:     }
 173:     unlink (fn);
 174: #else
 175:     if (f != 0)                     /* check error message */
 176:     {
 177:     fprintf ("Couldn't deliver mail; draft left in %s\n", fn);
 178:     fflush (stdout);
 179:     sleep (2);
 180:     }
 181:     else
 182:     unlink (fn);
 183: #endif	SUPERMAILER
 184: 
 185:     return 0;
 186: }

Defined functions

mailit defined in line 26; used 2 times

Defined variables

rcsid defined in line 5; never used
Last modified: 1985-10-30
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1126
Valid CSS Valid XHTML 1.0 Strict