📄 popser.c
字号:
bp += strlen (bp);#else switch (code) { case OK: case NOTOK: (void) sprintf (bp, "%s%s", code == OK ? "+OK" : "-ERR", fmt ? " " : ""); bp += strlen (bp); break; default: /* only happens in pop2 */ *bp++ = code; code = OK; }#endif if (fmt) { (void) sprintf (bp, fmt, a, b, c, d); bp += strlen (bp); } putline (buffer, output); return code;}/* VARARGS1 */static multiline (fmt, a, b, c, d)char *fmt, *a, *b, *c, *d;{ register char *cp; char buffer[BUFSIZ + TRMLEN]; (void) strcpy (buffer, TRM); (void) sprintf (cp = (buffer + TRMLEN), fmt, a, b, c, d); if (strncmp (cp, TRM, TRMLEN) == 0) cp = buffer; putline (cp, output);}static multiend () { putline (TRM, output);}/* */static int getline (s, n, iop)register char *s;register int n;register FILE *iop;{ register int c; register char *p; p = s; while (--n > 0 && (c = fgetc (iop)) != EOF) { while (c == IAC) { (void) fgetc (iop); c = fgetc (iop); } if ((*p++ = c) == '\n') break; } if (ferror (iop)) return NOTOK; if (c == EOF && p == s) return DONE; if (debug) { if (*--p == '\n') *p = 0; padvise (NULLCP, LOG_DEBUG, "<--- %s", s); if (*p == 0) *p = '\n'; p++; } *p++ = 0; return OK;}static putline (s, iop)register char *s;register FILE *iop;{ (void) fprintf (iop, "%s\r\n", s); if (debug) padvise (NULLCP, LOG_DEBUG, "---> %s", s); (void) fflush (iop);}/* ARGSUSED */static TYPESIG pipeser (sig, code, sc)int sig;long code;struct sigcontext *sc;{ padvise (NULLCP, LOG_WARNING, "lost connection"); _exit (NOTOK);}/* *//* Some people don't want to use the POP delivery agent with Sendmail * if they're going to run POP. Sendmail writes maildrops in the old * UUCP format, and popd doesn't know how to read them. These people * really should do what the MH manual says -- run the pop delivery * agent and be done with it. Some things never die. * * A real fix would be to make uip/dropsbr.c should use the same methods * as sbr/m_getfld.c to determine the format of maildrops and read & * write them. Unfortunately, it'll take a lot of work to bring it into * the fold. 20Mar90/JLR * * I really really hate to add this, but this lets stuff popd read * UUCP style maildrops as well as MMDF (ctrl/A) style maildrops. It was * contributed by Steve Dempsey <steved@longs.LANCE.ColoState.Edu>. * * Here's what he says: * * Ideally, one should be able to do it with the mmdelim strings, but * the MH parser is not intelligent enough to do this. You have at * least a couple of choices: * * - use aliases to deliver mail to POP users (user: user@pop) and * install the POP delivery agent - should work well with sendmail. * - fix the POP server! * * We have all mail sent to one machine and users are given two options: * * - MH on any machine. * - any user agent on the postoffice machine. * * Most of our workstations run xmh and users find that to be sufficient. * New users are only taught to use MH, and a very few old timers stay * with BSD mail. In any case, several agents are available at the cost * of a telnet/rlogin if a user does not like MH. * * I have made the changes to the POP server (MH-6.6/support/pop/popser.c) * to look for the `\n\nFrom ' delimiter instead of the ^A's, using some * code from the BSD agent. Context diff is included below. When this * is installed, you just go back to the normal localmail and get rid of * slocal completely. * * I have not tried this modification with anything but the MH client, * but it should work. Nothing in the POP protocol changes; the server * just has different criteria for delimiting messages in the mailbox. * If you decide to use this, I'd like to know what happens. * * Steve Dempsey, Center for Computer Assisted Engineering * Colorado State University, Fort Collins, CO 80523 +1 303 491 0630 * INET: steved@longs.LANCE.ColoState.Edu, dempsey@handel.CS.ColoState.Edu * boulder!ccncsu!longs.LANCE.ColoState.Edu!steved, ...!ncar!handel!dempsey *//* From: Jim Reid <jim@computer-science.strathclyde.ac.UK> * * MH-6.7 does not support MMDF-style mailboxes with POP as claimed. It * appears that when code was added to popser.c to support UNIX-style * mailboxes, the old behaviour was lost. i.e. The new popd worked with * UNIX-style mailboxes, but not MMDF ones. Users would get "format error" * error messages if they tried to inc a remote MMDF-style mailbox because * the pop daemon didn't want to know or like the MMDF message delimiters. *//* So... Now there's an incredible hack in mhconfig.c to define POPUUMBOX * in support/pop/Makefile if we're using Sendmail. This causes this * UUCP-mbox reading code to be used here. Ugh. 05Nov90/JLR *//* */#ifdef POPUUMBOX/* from dropsbr.c - read from a mailbox - pop server version *//* ALMOST IDENTICAL to mbx_read */static int pmbx_read (fp, pos, drops, noisy)register FILE *fp;register long pos;struct drop **drops;int noisy;{ register int len, size; register char *bp; char buffer[BUFSIZ]; register struct drop *cp, *dp, *ep, *pp;/* MTR: tsk, tsk, tsk... */ (void) fseek (fp, pos, 0); if (fgets (buffer, sizeof buffer, fp) && strcmp (buffer, mmdlm1) == 0) return mbx_read (fp, pos, drops, noisy); /* get drop storage */ pp = (struct drop *) calloc ((unsigned) (len = MAXFOLDER), sizeof *dp); if (debug) padvise (NULLCP, LOG_DEBUG, "pmbx_read (%d, %ld, %d, %d)", fp, pos,drops,noisy); if (pp == NULL) { if (noisy) admonish (NULLCP, "unable to allocate drop storage"); return NOTOK; } /* rewind drop file */ (void) fseek (fp, pos, 0); if (debug) padvise (NULLCP, LOG_DEBUG, "rewind maildrop"); /* read a buffer */ for (ep = (dp = pp) + len - 1; fgets (buffer, sizeof buffer, fp);) { size = 0; /* if beginning of msg then mark it */ if (p_ishead(buffer)) /*(strcmp (buffer, mmdlm1) == 0)*/ { /* (don't) inc pos to msg start, mark it */ /*pos += ld1;*/ dp -> d_start = pos; pos += strlen(buffer); /* inc pos after marking head */ } else { /* didn't find it; mark it anyway */ dp -> d_start = pos, pos += (long) strlen (buffer); /* count newlines and inc size if any found */ for (bp = buffer; *bp; bp++, size++) if (*bp == '\n') size++; } /* read more lines... */ while (fgets (buffer, sizeof buffer, fp) != NULL) /* found end? */ if (p_ishead(buffer)) /*(strcmp (buffer, mmdlm2) == 0)*/ { /* out of loop */ (void) fseek (fp, pos, 0); break; } else { /* add buffer size to pos */ pos += (long) strlen (buffer); /* count newlines.... */ for (bp = buffer; *bp; bp++, size++) if (*bp == '\n') size++; } if (dp -> d_start != pos) { /* do this if pos was actually incremented; got some text */ dp -> d_id = 0; dp -> d_size = size; /* save the stuff we got */ dp -> d_stop = pos; dp++; } /* (don't) advance pos */ /* pos += ld2; */ /* need more storage.... */ if (dp >= ep) { register int curlen = dp - pp; cp = (struct drop *) realloc ((char *) pp, (unsigned) (len += MAXFOLDER) * sizeof *pp); if (cp == NULL) { if (noisy) admonish (NULLCP, "unable to allocate drop storage"); free ((char *) pp); return 0; } dp = cp + curlen, ep = (pp = cp) + len - 1; } } /* return unused stuff */ if (dp == pp) free ((char *) pp); else *drops = pp; return (dp - pp);}/* * The remainder of this file adapted from: * * head.c 5.2 (Berkeley) 6/21/85 */struct p_hdline { char *l_from; /* The name of the sender */ char *l_tty; /* His tty string (if any) */ char *l_date; /* The entire date string */};/* * * See if position in a file is a mail header. * Return true if yes. Note the extreme pains to * accomodate all funny formats. */#define NOSTR ((char *) 0) /* Null string pointer */static char *p_copyin();static char *p_copy();static p_ishead(buffer)char buffer[];{register char *cp;struct p_hdline hl;char linebuf[BUFSIZ];char parbuf[BUFSIZ]; strcpy(linebuf,buffer); cp = linebuf; if (linebuf[0]=='F') padvise (NULLCP, LOG_DEBUG, "ishead: '%s'",linebuf); if (strncmp("From ", cp, 5) != 0) return(0); padvise (NULLCP, LOG_DEBUG, "Fromline..."); /* get full header */ p_parse(cp, &hl, parbuf); if (hl.l_from == NOSTR || hl.l_date == NOSTR) { padvise (NULLCP, LOG_DEBUG, "Fromline...NODATE"); return(0); } if (!p_isdate(hl.l_date)) { padvise (NULLCP, LOG_DEBUG, "Fromline...BADDATE %s", hl.l_date); return(0); } /* I guess we got it! */ padvise (NULLCP, LOG_DEBUG, "got a head.. "); return(1);}/* * Split a headline into its useful components. * Copy the line into dynamic string space, then set * pointers into the copied line in the passed headline * structure. Actually, it scans. */static p_parse(line, hl, pbuf) char line[], pbuf[]; struct p_hdline *hl;{ register char *cp, *dp; char *sp; char word[BUFSIZ]; char * p_nextword(); hl->l_from = NOSTR; hl->l_tty = NOSTR; hl->l_date = NOSTR; cp = line; sp = pbuf; /* * Skip the first "word" of the line, which should be "From" * anyway. */ cp = p_nextword(cp, word); dp = p_nextword(cp, word); if (!(strcmp(word, "")==0)) hl->l_from = p_copyin(word, &sp); /* UNLIKELY */ if (strncmp(dp, "tty", 3) == 0) { cp = p_nextword(dp, word); hl->l_tty = p_copyin(word, &sp); if (cp != NOSTR) hl->l_date = p_copyin(cp, &sp); } /* USUAL */ else if (dp != NOSTR) hl->l_date = p_copyin(dp, &sp);}/* * Copy the string on the left into the string on the right * and bump the right (reference) string pointer by the length. * Thus, dynamically allocate space in the right string, copying * the left string into it. */static char *p_copyin(src, space) char src[]; char **space;{ register char *cp, *top; register int s; s = strlen(src); cp = *space; top = cp; strcpy(cp, src); cp += s + 1; *space = cp; return(top);}/* * Collect a liberal (space, tab delimited) word into the word buffer * passed. Also, return a pointer to the next word following that, * or (empty) if none follow. */static char *p_nextword(wp, wbuf) char wp[], wbuf[];{ register char *cp, *cp2; if ((cp = wp) == NOSTR) { p_copy("", wbuf); return(NOSTR); } cp2 = wbuf; while (!any(*cp, " \t") && *cp != '\0') if (*cp == '"') { *cp2++ = *cp++; while (*cp != '\0' && *cp != '"') *cp2++ = *cp++; if (*cp == '"') *cp2++ = *cp++; } else *cp2++ = *cp++; *cp2 = '\0'; while (any(*cp, " \t")) cp++; if (*cp == '\0') return(NOSTR); return(cp);}/* * Copy str1 to str2, return pointer to null in str2. */static char *p_copy(str1, str2) char *str1, *str2;{ register char *s1, *s2; s1 = str1; s2 = str2; while (*s1) *s2++ = *s1++; *s2 = 0; return(s2);}#define L 1 /* A lower case char */#define S 2 /* A space */#define D 3 /* A digit */#define O 4 /* An optional digit or space */#define C 5 /* A colon */#define N 6 /* A new line */#define U 7 /* An upper case char */static char p_ctypes[] = {U,L,L,S,U,L,L,S,O,D,S,D,D,C,D,D,C,D,D,S,D,D,D,D,0};/* T h u S e p 2 9 1 5 : 2 0 : 1 9 1 9 8 8 */static char p_tmztyp[] = {U,L,L,S,U,L,L,S,O,D,S,D,D,C,D,D,C,D,D,S,U,U,U,S,D,D,D,D,0};/* T h u S e p 2 9 1 5 : 2 0 : 1 9 M S T 1 9 8 8 */static p_isdate(date) char date[];{ register char *cp; cp = date; if (p_cmatch(cp, p_ctypes)) return(1); return(p_cmatch(cp, p_tmztyp));}/* * Match the given string against the given template. * Return 1 if they match, 0 if they don't */static p_cmatch(str, temp) char str[], temp[];{ register char *cp, *tp; register int c; cp = str; tp = temp; while (*cp != '\0' && *tp != 0) { c = *cp++; switch (*tp++) { case L: if (c < 'a' || c > 'z') return(0); break; case U: if (c < 'A' || c > 'Z') return(0); break; case S: if (c != ' ') return(0); break; case D: if (!isdigit(c)) return(0); break; case O: if (c != ' ' && !isdigit(c)) return(0); break; case C: if (c != ':') return(0); break; case N: if (c != '\n') return(0); break; } } if ((*cp != '\0' && *cp != '\n') || *tp != 0) return(0); return(1);}static any(ch, str) char *str;{ register char *f; register c; f = str; c = ch; while (*f) if (c == *f++) return(1); return(0);}#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -