9 date 92.10.28.18.52.45; author jromine; state Exp;
14 date 92.10.28.18.20.47; author jromine; state Exp;
19 date 92.05.20.22.11.32; author jromine; state Exp;
24 date 92.05.19.21.05.55; author jromine; state Exp;
29 date 92.03.03.17.09.57; author jromine; state Exp;
34 date 92.02.08.00.10.26; author jromine; state Exp;
39 date 92.02.04.21.50.37; author jromine; state Exp;
44 date 92.02.04.21.50.14; author jromine; state Exp;
56 @h/local.h includes sys/stat.h -- don't include it twice
59 @/* popi.c - POP initiator - for MPOP */
61 static char ident[] = "@@(#)$Id: popi.c,v 1.7 1992/10/28 18:20:47 jromine Exp jromine $";
65 #include "../h/formatsbr.h"
66 #include "../h/scansbr.h"
69 #include <sys/types.h>
71 #include "../h/local.h"
75 #include "../zotnet/mts.h"
80 #define RPOPminc(a) (a)
86 #define APOPminc(a) (a)
92 #define BPOPminc(a) (a)
98 #define BULKminc(a) (a)
100 #define BULKminc(a) 0
103 static struct swit switches[] = {
105 "apop", APOPminc (-4),
107 "noapop", APOPminc (-6),
110 "auto", BPOPminc(-4),
112 "noauto", BPOPminc(-6),
115 "bulk directory", BULKminc(-4),
118 "form formatfile", 0,
127 "mshproc program", 0,
130 "rpop", RPOPminc (-4),
132 "norpop", RPOPminc (-6),
148 static char *bulksw = NULLCP;
149 static int snoop = 0;
150 static int width = 0;
152 static char mailname[BUFSIZ];
154 static char *nfs = NULL;
156 static struct msgs *mp;
160 extern char response[];
187 invo_name = r1bindex (argv[0], '/');
188 mts_init (invo_name);
189 if (pophost && *pophost)
191 if ((cp = getenv ("MHPOPDEBUG")) && *cp)
193 if ((cp = m_find (invo_name)) != NULL) {
194 ap = brkstring (cp = getcpy (cp), " ", "\n");
195 ap = copyip (ap, arguments);
199 (void) copyip (argv + 1, ap);
202 rpop = getuid () && !geteuid ();
206 while (cp = *argp++) {
208 switch (smatch (++cp, switches)) {
210 ambigsw (cp, switches);
213 adios (NULLCP, "-%s unknown", cp);
215 (void) sprintf (buf, "%s [+folder] [switches]", invo_name);
216 help (buf, switches);
227 if (!(bulksw = *argp++) || *bulksw == '-')
228 adios (NULLCP, "missing argument to %s", argp[-2]);
232 if (!(form = *argp++) || *form == '-')
233 adios (NULLCP, "missing argument to %s", argp[-2]);
237 if (!(format = *argp++) || *format == '-')
238 adios (NULLCP, "missing argument to %s", argp[-2]);
243 if (!(cp = *argp++) || *cp == '-')
244 adios (NULLCP, "missing argument to %s", argp[-2]);
249 if (!(host = *argp++) || *host == '-')
250 adios (NULLCP, "missing argument to %s", argp[-2]);
253 if (!(user = *argp++) || *user == '-')
254 adios (NULLCP, "missing argument to %s", argp[-2]);
269 if (!(mshproc = *argp++) || *mshproc == '-')
270 adios (NULLCP, "missing argument to %s", argp[-2]);
273 if (*cp == '+' || *cp == '@@') {
275 adios (NULLCP, "only one folder at a time!");
277 folder = path (cp + 1, *cp == '+' ? TFOLDER : TSUBCWF);
280 adios (NULLCP, "usage: %s [+folder] [switches]", invo_name);
286 adios (NULLCP, "usage: %s -host \"host\"", invo_name);
298 (void) setuid (getuid ());
299 ruserpass (host, &user, &pass);
301 (void) sprintf (mailname, "PO box for %s@@%s", user, host);
303 if (pop_init (host, user, pass, snoop, rpop) == NOTOK)
304 adios (NULLCP, "%s", response);
306 (void) setuid (getuid ());
308 nfs = new_fs (form, format, FORMAT);
310 if (!m_find ("path"))
311 free (path ("./", TFOLDER));
312 if (!folder && !(folder = m_find (inbox)))
314 maildir = m_maildir (folder);
316 if (stat (maildir, &st) == NOTOK) {
318 adios (maildir, "error on folder");
319 cp = concat ("Create folder \"", maildir, "\"? ", NULLCP);
320 if (noisy && !getanswer (cp))
323 if (!makedir (maildir))
324 adios (NULLCP, "unable to create folder %s", maildir);
327 if (chdir (maildir) == NOTOK)
328 adios (maildir, "unable to change directory to");
329 if (!(mp = m_gmsg (folder)))
330 adios (NULLCP, "unable to read folder %s", folder);
341 m_replace (pfolder, folder);
353 static struct swit popicmds[] = {
397 printf ("(%s) ", invo_name);
398 for (cp = buffer; (i = getchar ()) != '\n'; ) {
400 (void) putchar ('\n');
407 if (cp < buffer + sizeof buffer - 2)
411 if (buffer[0] == '\0')
413 if (buffer[0] == '?') {
414 printf ("commands:\n");
415 printsw (ALL, popicmds, "");
416 printf ("type CTRL-D or use \"quit\" to leave %s\n", invo_name);
420 if (cp = index (buffer, ' '))
422 switch (i = smatch (buffer, popicmds)) {
424 ambigsw (buffer, popicmds);
427 printf ("%s unknown -- type \"?\" for help\n", buffer);
441 (void) pop_command ("%s%s", popicmds[i].sw, cp ? cp : "");
442 printf ("%s\n", response);
448 if (pop_command ("%s%s", popicmds[i].sw, cp ? cp : "")
450 printf ("%s\n", response);
453 switch (pop_multiline ()) {
455 (void) strcpy (response, ".");
458 printf ("%s\n", response);
462 printf ("%s\n", response);
472 advise (NULLCP, "missing argument to %s", buffer);
475 retr_action (NULLCP, OK);
476 (void) pop_retr (atoi (++cp), retr_action);
477 retr_action (NULLCP, DONE);
478 printf ("%s\n", response);
490 for (dp = nfs, i = 0; *dp; dp++, i++)
491 if (*dp == '\\' || *dp == '"' || *dp == '\n')
494 if ((ep = malloc ((unsigned) i)) == NULL)
495 adios (NULLCP, "out of memory");
496 for (dp = nfs, fp = ep; *dp; dp++) {
498 *fp++ = '\\', *fp++ = 'n';
501 if (*dp == '"' || *dp == '\\')
507 (void) pop_command ("xtnd scan %d \"%s\"", width, ep);
508 printf ("%s\n", response);
525 static int retr_action (rsp, flag)
536 if ((mp = m_remsg (mp, 0, msgnum = mp -> hghmsg + 1)) == NULL)
537 adios (NULLCP, "unable to allocate folder storage");
539 cp = getcpy (m_name (mp -> hghmsg + 1));
540 if ((fp = fopen (cp, "w+")) == NULL)
541 adios (cp, "unable to write");
542 (void) chmod (cp, m_gmprot ());
548 if (fstat (fileno (fp), &st) != NOTOK && st.st_size > 0) {
549 mp -> msgstats[msgnum] = EXISTS | UNSEEN;
550 mp -> msgflags |= SEQMOD;
553 advise (cp, "write error on");
554 mp -> hghmsg = msgnum;
559 (void) fclose (fp), fp = NULL;
560 free (cp), cp = NULL;
566 fprintf (fp, "%s\n", rsp);
580 if (pop_fd (buf1, buf2) == NOTOK)
581 adios (NULLCP, "%s", response);
584 vec[vecp++] = r1bindex (mshproc, '/');
586 switch (child_id = fork ()) {
588 adios ("fork", "unable to");
591 vec[vecp++] = "-popread";
593 vec[vecp++] = "-popwrite";
595 vec[vecp++] = "-idname";
596 vec[vecp++] = mailname;
597 vec[vecp++] = mailname;
599 (void) execvp (mshproc, vec);
600 fprintf (stderr, "unable to exec ");
605 (void) pidXwait (child_id, mshproc);
614 #include "../zotnet/mts.h"
615 #include "../mts/sendmail/smail.h"
618 static int dselect (d)
619 register struct direct *d;
623 if ((i = strlen (d -> d_name)) < sizeof "smtp"
624 || strncmp (d -> d_name, "smtp", sizeof "smtp" - 1))
626 return ((i -= (sizeof ".bulk" - 1)) > 0
627 && !strcmp (d -> d_name + i, ".bulk"));
631 static int dcompar (d1, d2)
638 if (stat ((*d1) -> d_name, &s1) == NOTOK)
640 if (stat ((*d2) -> d_name, &s2) == NOTOK)
642 return ((int) (s1.st_mtime - s2.st_mtime));
646 static do_bulk (host)
653 struct direct **namelist;
655 if (chdir (bulksw) == NOTOK)
656 adios (bulksw, "unable to change directory to");
658 if ((n = scandir (".", &namelist, dselect, dcompar)) == NOTOK)
659 adios (bulksw, "unable to scan directory");
662 for (i = 0; i < n; i++) {
663 register struct direct *d = namelist[i];
666 if (rp_isbad (retval = sm_init (NULLCP, host, 1, 1, snoop)))
667 adios (NULLCP, "problem initializing server: %s",
673 switch (retval = sm_bulk (d -> d_name)) {
675 if (rp_isbad (retval))
676 adios (NULLCP, "problem delivering msg %s: %s",
677 d -> d_name, rp_string (retval));
682 advise (NULLCP, "msg %s: %s", d -> d_name, rp_string (retval));
691 struct direct **newlist;
693 while ((l = scandir (".", &newlist, dselect, dcompar)) > OK) {
696 for (j = 0; j < l; j++) {
697 register struct direct *d = newlist[j];
699 for (i = 0; i < n; i++)
700 if (strcmp (d -> d_name, namelist[i] -> d_name) == 0)
703 switch (retval = sm_bulk (d -> d_name)) {
705 if (rp_isbad (retval))
706 adios (NULLCP, "problem delivering msg %s: %s",
707 d -> d_name, rp_string (retval));
712 advise (NULLCP, "msg %s: %s", d -> d_name,
721 for (i = 0; i < n; i++)
722 free ((char *) namelist[i]);
723 free ((char *) namelist);
724 namelist = newlist, n = l;
732 if (sm == OK && rp_isbad (retval = sm_end (OK)))
733 adios (NULLCP, "problem finalizing server: %s", rp_string (retval));
735 for (i = 0; i < n; i++)
736 free ((char *) namelist[i]);
737 free ((char *) namelist);
739 free ((char *) namelist);
754 static char ident[] = "@@(#)$Id: popi.c,v 1.6 1992/05/20 22:11:32 jromine Exp jromine $";
758 #include "../h/local.h"
769 static char ident[] = "@@(#)$Id: popi.c,v 1.5 1992/05/19 21:05:55 jromine Exp jromine $";
783 /* popi.c - POP initiator */
786 static char ident[] = "@@(#)$Id: popi.c,v 1.4 1992/03/03 17:09:57 jromine Exp jromine $";
797 static char ident[] = "@@(#)$Id: popi.c,v 1.3 1992/02/08 00:10:26 jromine Exp jromine $";
807 if (buffer[0] == NULL)
824 static char ident[] = "@@(#)$Id: popi.c,v 1.2 1992/02/04 21:50:37 jromine Exp jromine $";
871 static char ident[] = "@@(#)$Id: scan.c,v 1.11 1992/02/03 22:45:20 jromine Exp $";
874 (void) sprintf (mailname, "POB/%s@@%s", user, host);