rfc822.c
上传用户:ycwykj01
上传日期:2007-01-04
资源大小:1819k
文件大小:61k
- /*
- * Program: RFC-822 routines (originally from SMTP)
- *
- * Author: Mark Crispin
- * Networks and Distributed Computing
- * Computing & Communications
- * University of Washington
- * Administration Building, AG-44
- * Seattle, WA 98195
- * Internet: MRC@CAC.Washington.EDU
- *
- * Date: 27 July 1988
- * Last Edited: 13 July 1999
- *
- * Sponsorship: The original version of this work was developed in the
- * Symbolic Systems Resources Group of the Knowledge Systems
- * Laboratory at Stanford University in 1987-88, and was funded
- * by the Biomedical Research Technology Program of the National
- * Institutes of Health under grant number RR-00785.
- *
- * Original version Copyright 1988 by The Leland Stanford Junior University
- * Copyright 1999 by the University of Washington
- *
- * Permission to use, copy, modify, and distribute this software and its
- * documentation for any purpose and without fee is hereby granted, provided
- * that the above copyright notices appear in all copies and that both the
- * above copyright notices and this permission notice appear in supporting
- * documentation, and that the name of the University of Washington or The
- * Leland Stanford Junior University not be used in advertising or publicity
- * pertaining to distribution of the software without specific, written prior
- * permission. This software is made available "as is", and
- * THE UNIVERSITY OF WASHINGTON AND THE LELAND STANFORD JUNIOR UNIVERSITY
- * DISCLAIM ALL WARRANTIES, EXPRESS OR IMPLIED, WITH REGARD TO THIS SOFTWARE,
- * INCLUDING WITHOUT LIMITATION ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
- * FITNESS FOR A PARTICULAR PURPOSE, AND IN NO EVENT SHALL THE UNIVERSITY OF
- * WASHINGTON OR THE LELAND STANFORD JUNIOR UNIVERSITY BE LIABLE FOR ANY
- * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
- * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
- * CONTRACT, TORT (INCLUDING NEGLIGENCE) OR STRICT LIABILITY, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- *
- */
- #include <ctype.h>
- #include <stdio.h>
- #include <time.h>
- #include "mail.h"
- #include "osdep.h"
- #include "rfc822.h"
- #include "misc.h"
- /* RFC-822 static data */
- char *errhst = ERRHOST; /* syntax error host string */
- /* Body formats constant strings, must match definitions in mail.h */
- char *body_types[TYPEMAX+1] = {
- "TEXT", "MULTIPART", "MESSAGE", "APPLICATION", "AUDIO", "IMAGE", "VIDEO",
- "MODEL", "X-UNKNOWN"
- };
- char *body_encodings[ENCMAX+1] = {
- "7BIT", "8BIT", "BINARY", "BASE64", "QUOTED-PRINTABLE", "X-UNKNOWN"
- };
- /* Token delimiting special characters */
- /* full RFC-822 specials */
- const char *rspecials = "()<>@,;:\"[].";
- /* body token specials */
- const char *tspecials = " ()<>@,;:\"[]./?=";
- /* Once upon a time, CSnet had a mailer which assigned special semantics to
- * dot in e-mail addresses. For the sake of that mailer, dot was added to
- * the RFC-822 definition of `specials', even though it had numerous bad side
- * effects:
- * 1) It broke mailbox names on systems which had dots in user names, such as
- * Multics and TOPS-20. RFC-822's syntax rules require that `Admin . MRC'
- * be considered equivalent to `Admin.MRC'. Fortunately, few people ever
- * tried this in practice.
- * 2) It required that all personal names with an initial be quoted, a widely
- * detested user interface misfeature.
- * 3) It made the parsing of host names be non-atomic for no good reason.
- * To work around these problems, the following alternate specials lists are
- * defined. hspecials and wspecials are used in lieu of rspecials, and
- * ptspecials are used in lieu of tspecials. These alternate specials lists
- * make the parser work a lot better in the real world. It ain't politically
- * correct, but it lets the users get their job done!
- */
- /* parse-word specials */
- const char *wspecials = " ()<>@,;:\"[]";
- /* parse-token specials for parsing */
- const char *ptspecials = " ()<>@,;:\"[]/?=";
- /* RFC822 writing routines */
- /* Write RFC822 header from message structure
- * Accepts: scratch buffer to write into
- * message envelope
- * message body
- */
- void rfc822_header (char *header,ENVELOPE *env,BODY *body)
- {
- if (env->remail) { /* if remailing */
- long i = strlen (env->remail);
- strcpy (header,env->remail);/* start with remail header */
- /* flush extra blank line */
- if (i > 4 && header[i-4] == ' 15') header[i-2] = ' ';
- }
- else *header = ' '; /* else initialize header to null */
- rfc822_header_line (&header,"Newsgroups",env,env->newsgroups);
- rfc822_header_line (&header,"Date",env,env->date);
- rfc822_address_line (&header,"From",env,env->from);
- rfc822_address_line (&header,"Sender",env,env->sender);
- rfc822_address_line (&header,"Reply-To",env,env->reply_to);
- rfc822_header_line (&header,"Subject",env,env->subject);
- if (env->bcc && !(env->to || env->cc))
- strcat (header,"To: undisclosed recipients: ; 15 12");
- rfc822_address_line (&header,"To",env,env->to);
- rfc822_address_line (&header,"cc",env,env->cc);
- /* bcc's are never written...
- * rfc822_address_line (&header,"bcc",env,env->bcc);
- */
- rfc822_header_line (&header,"In-Reply-To",env,env->in_reply_to);
- rfc822_header_line (&header,"Message-ID",env,env->message_id);
- rfc822_header_line (&header,"Followup-to",env,env->followup_to);
- rfc822_header_line (&header,"References",env,env->references);
- if (body && !env->remail) { /* not if remail or no body structure */
- strcat (header,"MIME-Version: 1.0 15 12");
- rfc822_write_body_header (&header,body);
- }
- strcat (header,"