13 void init_mail_header(struct mail_header
*hdr
)
15 memset(hdr
->from
, 0, sizeof(hdr
->from
));
16 memset(hdr
->subject
, 0, sizeof(hdr
->subject
));
18 hdr
->body_offset
= 0L;
22 * If no Content-Type header field is specified, default to:
23 * Content-type: text/plain; charset=us-ascii
25 hdr
->mime
.type
= MIME_TYPE_TEXT
;
26 hdr
->mime
.type_charset
= MIME_TYPE_CHARSET_US_ASCII
;
27 hdr
->mime
.subtype
= MIME_SUBTYPE_PLAIN
;
28 hdr
->mime
.disposition
= MIME_DISPOSITION_UNKNOWN
;
30 /* [RFC2045] "Content-Transfer-Encoding: 7BIT" is assumed if the
31 * Content-Transfer-Encoding header field is not present.
32 * ... If a Content-Transfer-Encoding header field appears as part
33 * of a message header, it applies to the entire body of that message.
34 * If a Content-Transfer-Encoding header field appears as part of an
35 * entity's headers, it applies only to the body of that entity.
36 * If an entity is of type "multipart" the Content-Transfer-Encoding
37 * is not permitted to have any value other than "7bit", "8bit" or
40 hdr
->mime
.transfer_encoding
= MIME_ENCODING_7BIT
;
43 void parse_mail_header(FILE *fh
, struct mail_header
*hdr
)
47 unsigned int fld_cont
; /* RFC822 Header field folding flag */
48 unsigned int fa_valid
; /* Valid From Address flag */
57 * Don't get a new line if we are coming from a folding
61 if (fgets(buf
, sizeof(buf
), fh
) == NULL
) {
68 if (!strncasecmp(buf
, "From:", 5)) {
69 rfc5322_extract_address(hdr
->from
, buf
, sizeof(hdr
->from
));
71 } else if (!strncasecmp(buf
, "Reply-to:", 9)) {
75 if (!rfc5322_extract_address(hdr
->from
, buf
, sizeof(hdr
->from
))) {
79 } else if (!strncasecmp(buf
, "Subject:", 8)) {
80 rfc5322_extract_subject(hdr
->subject
, buf
, sizeof(hdr
->subject
));
81 } else if (!strncasecmp(buf
, "Date:", 5)) {
82 hdr
->date
= rfc822_parsedt(buf
);
83 } else if (!strncasecmp(buf
, "Content-Type:", 13)) {
84 mime_content_type(buf
+ 14, &hdr
->mime
);
86 while (fgets(buf
, sizeof(buf
), fh
)) {
87 if (rfc822_check_field_folding(buf
)) {
88 /* Decode folded line */
89 mime_content_type_parameter(buf
, &hdr
->mime
);
95 } else if (!strncasecmp(buf
, "Content-Disposition:", 20)) {
96 mime_content_disposition(buf
+ 21, &hdr
->mime
);
97 } else if (!strncasecmp(buf
, "Content-Transfer-Encoding:", 26)) {
98 mime_content_transfer_encoding(buf
+ 27, &hdr
->mime
);
100 /*printf("[SKIP] ------- %s", buf);*/
102 } while (!rfc822_check_header_end(buf
));
104 /* If a valid 'from' address was found calc the MD5 of this address */
106 crlf
= strrchr(hdr
->from
, '\n');
110 md5_calc_sum(hdr
->from
, hdr
->addr_md5
);
113 /* Get file offset of the message body */
114 hdr
->body_offset
= ftell(fh
);