1: #include "parms.h"
   2: #include "structs.h"
   3: 
   4: #ifdef  RCSIDENT
   5: static char rcsid[] = "$Header: mailit.c,v 1.8 87/07/01 13:47:42 paul Exp $";
   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:  *	added code to handle the MODERATED flag.
  24:  *		rich $alz, mirror systems, august 19, 1985
  25:  *
  26:  */
  27: 
  28: mailit (io, where, author, date, title, toauth, wtext)
  29: struct io_f *io;
  30: struct daddr_f *where;
  31: struct auth_f  *author;
  32: struct when_f  *date;
  33: char   *title;
  34: /* toauth - true if mail to author of note */
  35: /* wtext - true is mail with text of note */
  36: {
  37:     char    buf[128];                   /* > 5 + 80 + 3 + 15 */
  38:     char    whoto[WDLEN + 1];               /* destination */
  39:     char   *command;                    /* mailer to use */
  40:     char    fn[20];                 /* hold scratch file name */
  41:     int     f;
  42:     char   *p;
  43:     FILE * txtfile;
  44: #ifdef  SUPERMAILER
  45:     char    subject[TITLEN + 20];           /* mailer subject */
  46: #endif
  47: 
  48:     if (toauth == MODERATED)
  49:     {
  50:     f = 1;
  51:     toauth = 0;
  52:     }
  53:     else
  54:     f = 0;
  55:     if (f && io -> descr.d_stat & MODERATED)
  56:     {
  57:     if (modaddress (io -> nf, whoto) == 1)
  58:     {
  59:         at (0, 1);
  60:         printf ("\nComplain to a guru; can't find moderator!\007\n");
  61:         fflush (stdout);
  62:         sleep (1);
  63:         return (-1);                /* no letter sent */
  64:     }
  65:     }
  66:     else if (toauth)
  67:     {
  68:     if (strcmp (author -> aname, "Anonymous") == 0)
  69:     {
  70:         printf ("Can't send to Anonymous\n");
  71:         fflush (stdout);
  72:         sleep (2);
  73:         return (-1);
  74:     }
  75:     if (strcmp (System, author -> asystem) != 0)
  76:     {
  77: #ifdef  USERHOST
  78:         sprintf (whoto, "%s@%s", author -> aname, author -> asystem);
  79: #else
  80:         sprintf (whoto, "%s!%s", author -> asystem, author -> aname);
  81: #endif	USERHOST
  82:     }
  83:     else
  84:         sprintf (whoto, "%s", author -> aname);
  85:     }
  86:     else
  87:     {
  88:     at (0, 1);
  89:     printf ("\nSend to whom? ");
  90:     if (gline (whoto, WDLEN) == 1)          /* will flush stdout */
  91:         return (-1);                /* no letter sent */
  92: 
  93:     }
  94: 
  95: #ifdef  SUPERMAILER
  96:     strcpy (subject, title);                /* build nice title */
  97:     for (p = subject; *p; p++)
  98:     if (*p == '"' || *p == '`')         /* problem avoidance */
  99:         *p = '\'';                  /* eliminate escapes */
 100: #endif	SUPERMAILER
 101: 
 102:     sprintf (fn, "/tmp/nfm%d", getpid ());
 103:     x ((txtfile = fopen (fn, "w")) == NULL, "mailit: creat tmp");
 104:     x (chmod (fn, 0666) < 0, "mailit: chmod tmp");
 105: 
 106:     if (wtext)                      /* add text if specified */
 107:     {
 108:     preptxt (io, txtfile, author, date, where, title);
 109:     }
 110: 
 111:     fclose (txtfile);
 112: 
 113:     if ((command = getenv ("MAILER")) == NULL)      /* override it? */
 114:     {
 115: #ifdef  SUPERMAILER
 116:     command = SUPERMAILER;              /* default mailer */
 117: #else
 118:     command = MAILER;               /* use default */
 119: #endif
 120:     }
 121:     at (0, 1);
 122: #ifdef  SUPERMAILER                 /* dumb mail interface */
 123:     if (wtext)                      /* do it hard way if with text */
 124:     {
 125: #endif
 126:     printf ("Edit letter:\n");
 127:     fflush (stdout);                /* clean out buffer */
 128: #ifndef FASTFORK
 129:     sprintf (buf, "%s %s", hised, fn);      /* build edit command */
 130:     dounix (buf, 1, 1);             /* call editor */
 131: #else
 132:     dounix (1, 1, hised, fn, 0, 0, 0);
 133: #endif	FASTFORK
 134: 
 135: 
 136:     f = 0;                      /* assume normal termination */
 137:     while (1)
 138:     {
 139:         sprintf (buf, "Send this to %s? (y/n):", whoto);
 140:         fflush (stdout);
 141:         if (askyn (buf) == 'y')
 142:         {
 143:         printf ("\nSending...\n");
 144:         fflush (stdout);
 145: #ifdef SUPERMAILER
 146:         sprintf (buf, "%s -s \"%s\" %s < %s", command, subject, whoto, fn);
 147: #else   !SUPERMAILER
 148:         sprintf (buf, "%s %s < %s", command, whoto, fn);
 149: #endif	SUPERMAILER
 150:                             /* make the command */
 151: #ifndef FASTFORK
 152:         f = dounix (buf, 1, 0);         /* mail the thing */
 153: #else
 154:         f = dounix (1, 0, DFLTSH, "-c", buf, 0, 0);
 155: /*
 156:  *	Can't let him use the C shell, since we don't escape the '!' in
 157:  *	remote addresses. RBE 6/21/82
 158:  */
 159: #endif
 160:         break;                  /* out of loop */
 161:         }
 162:         else                    /* not to him... */
 163:         {
 164:         /*
 165: 		 * let him pick a new addressee
 166: 		 */
 167:         printf ("\nSend to whom? ");
 168:         if (gline (whoto, WDLEN) == 1)      /* will flush stdout */
 169:             break;              /* don't send */
 170: 
 171:         }
 172:     }
 173: #ifdef  SUPERMAILER                 /* simple case for SUPERMAILER */
 174:     }
 175:     else
 176:     {
 177:     printf ("%s %s\n", command, whoto);
 178:     fflush (stdout);                /* empty buffers */
 179:     sprintf (buf, "%s %s", command, whoto);
 180: #ifndef FASTFORK
 181:     f = dounix (buf, 1, 1);             /* set the uid & tty */
 182: #else
 183:     f = dounix (1, 1, DFLTSH, "-c", buf, 0, 0); /* do it */
 184: #endif	FASTFORK
 185:     }
 186: #endif	SUPERMAILER
 187: 
 188: #ifdef  SUPERMAILER
 189:     if (f != 0)                     /* pause for error message */
 190:     {
 191:     fflush (stdout);
 192:     sleep (2);
 193:     }
 194:     unlink (fn);
 195: #else
 196:     if (f != 0)                     /* check error message */
 197:     {
 198:     fprintf ("Couldn't deliver mail; draft left in %s\n", fn);
 199:     fflush (stdout);
 200:     sleep (2);
 201:     }
 202:     else
 203:     unlink (fn);
 204: #endif	SUPERMAILER
 205: 
 206:     return 0;
 207: }
 208: 
 209: modaddress (notesname, address)
 210:     char *notesname;
 211:     char *address;
 212: {
 213:     char buff[WDLEN];
 214:     register FILE *mods;
 215:     register char *p;
 216: 
 217:     sprintf (buff, "%s/%s/moderators", MSTDIR, UTILITY);
 218: 
 219:     if ((mods = fopen (buff, "r")) == NULL)
 220:     {
 221:     printf ("Can't open moderators file!\n");
 222:     return 1;
 223:     }
 224: 
 225:     while (fgets ( buff, sizeof buff, mods))
 226:     {
 227:     /* read lines of the form <name><whitespace>path; blanks and lines */
 228:     /* starting with "#" are comments. */
 229:     if (buff[0] == '\0' || buff[0] == '#'
 230:      || (((p=index(buff, ' ')) == NULL) && (p=index(buff, '\t')) == NULL))
 231:         continue;
 232:     *p++ = '\0';                    /* split into halves */
 233:     while (*p == ' ' || *p == '\t')
 234:         p++;                    /* skip whitespace */
 235:     if (!strcmp (notesname, buff))
 236:     {
 237:         strcpy (address, p);
 238:         address[strlen(address) - 1] = '\0';    /* kill the \n */
 239:         fclose (mods);
 240:         return 0;
 241:     }
 242:     }
 243: 
 244:     fclose (mods);
 245:     return 1;
 246: }

Defined functions

mailit defined in line 28; used 3 times
modaddress defined in line 209; used 1 times
  • in line 57

Defined variables

rcsid defined in line 5; never used
Last modified: 1987-07-01
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 3068
Valid CSS Valid XHTML 1.0 Strict