X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=handler.c;h=27bfb08ba53f13b3cd89c7e92ec7e232f60a45ed;hp=fe2a0f7ffbfe880b62b80a18cefc78224440cc5b;hb=7d29626ce4e1fa932c6349c7253e6f774df069fc;hpb=35f4e8cefa22d98782a720e4df428a1ce3be2237 diff --git a/handler.c b/handler.c index fe2a0f7..27bfb08 100644 --- a/handler.c +++ b/handler.c @@ -7,28 +7,15 @@ * please see the file GPL in the top level source directory. */ -#if HAVE_CONFIG_H -# include "config.h" -#endif - -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include +#include #include #include #include +#include + #include "mutt.h" #include "recvattach.h" #include "handler.h" @@ -152,7 +139,7 @@ static void qp_decode_line (char *dest, char *src, ssize_t * l, int last) * */ -void mutt_decode_quoted (STATE * s, long len, int istext, iconv_t cd) +static void mutt_decode_quoted (STATE * s, long len, int istext, iconv_t cd) { char line[STRING]; char decline[2 * STRING]; @@ -283,16 +270,14 @@ void mutt_decode_base64 (STATE * s, long len, int istext, iconv_t cd) state_reset_prefix (s); } -unsigned char decode_byte (char ch) +static unsigned char decode_byte(int ch) { - if (ch == 96) - return 0; - return ch - 32; + return ch == 96 ? 0 : ch - 32; } -void mutt_decode_uuencoded (STATE * s, long len, int istext, iconv_t cd) +static void mutt_decode_uuencoded (STATE * s, long len, int istext, iconv_t cd) { - char tmps[SHORT_STRING]; + char tmps[STRING]; char linelen, c, l, out; char *pt; char bufi[BUFI_SIZE]; @@ -315,13 +300,13 @@ void mutt_decode_uuencoded (STATE * s, long len, int istext, iconv_t cd) if (!m_strncmp(tmps, "end", 3)) break; pt = tmps; - linelen = decode_byte (*pt); + linelen = decode_byte(*pt); pt++; for (c = 0; c < linelen;) { for (l = 2; l <= 6; l += 2) { - out = decode_byte (*pt) << l; + out = decode_byte(*pt) << l; pt++; - out |= (decode_byte (*pt) >> (6 - l)); + out |= (decode_byte(*pt) >> (6 - l)); bufi[k++] = out; c++; if (c == linelen) @@ -353,22 +338,21 @@ static struct { const char *tag_name; int index; } EnrichedTags[] = { - { - "param", RICH_PARAM}, { - "bold", RICH_BOLD}, { - "italic", RICH_ITALIC}, { - "underline", RICH_UNDERLINE}, { - "nofill", RICH_NOFILL}, { - "excerpt", RICH_EXCERPT}, { - "indent", RICH_INDENT}, { - "indentright", RICH_INDENT_RIGHT}, { - "center", RICH_CENTER}, { - "flushleft", RICH_FLUSHLEFT}, { - "flushright", RICH_FLUSHRIGHT}, { - "flushboth", RICH_FLUSHLEFT}, { - "color", RICH_COLOR}, { - "x-color", RICH_COLOR}, { - NULL, -1} + {"param", RICH_PARAM}, + {"bold", RICH_BOLD}, + {"italic", RICH_ITALIC}, + {"underline", RICH_UNDERLINE}, + {"nofill", RICH_NOFILL}, + {"excerpt", RICH_EXCERPT}, + {"indent", RICH_INDENT}, + {"indentright", RICH_INDENT_RIGHT}, + {"center", RICH_CENTER}, + {"flushleft", RICH_FLUSHLEFT}, + {"flushright", RICH_FLUSHRIGHT}, + {"flushboth", RICH_FLUSHLEFT}, + {"color", RICH_COLOR}, + {"x-color", RICH_COLOR}, + {NULL, -1} }; struct enriched_state { @@ -496,7 +480,7 @@ static void enriched_flush (struct enriched_state *stte, int wrap) stte->line_max = stte->line_used; p_realloc(&stte->line, stte->line_max + 1); } - strcat (stte->line, stte->buffer); /* __STRCAT_CHECKED__ */ + m_strcat(stte->line, stte->line_max + 1, stte->buffer); stte->line_len += stte->word_len; stte->word_len = 0; stte->buff_used = 0; @@ -554,8 +538,7 @@ static void enriched_putc (int c, struct enriched_state *stte) else { stte->buffer[stte->buff_used++] = c; } - } - else { + } else { stte->buffer[stte->buff_used++] = c; } stte->word_len++; @@ -644,7 +627,7 @@ static void enriched_set_flags (const char *tag, struct enriched_state *stte) } } -int text_enriched_handler (BODY * a, STATE * s) +static int text_enriched_handler (BODY * a, STATE * s) { enum { TEXT, LANGLE, TAG, BOGUS_TAG, NEWLINE, ST_EOF, DONE @@ -781,14 +764,12 @@ static int alternative_handler (BODY * a, STATE * s) mustfree = 1; fstat (fileno (s->fpin), &st); - b = mutt_new_body (); + b = body_new(); b->length = (long) st.st_size; - b->parts = mutt_parse_multipart (s->fpin, - mutt_get_parameter ("boundary", - a->parameter), - (long) st.st_size, - ascii_strcasecmp ("digest", - a->subtype) == 0); + b->parts = mutt_parse_multipart(s->fpin, + parameter_getval(a->parameter, "boundary"), + (long)st.st_size, + !ascii_strcasecmp("digest", a->subtype)); } else b = a; @@ -905,7 +886,7 @@ static int alternative_handler (BODY * a, STATE * s) } if (mustfree) - mutt_free_body (&a); + body_list_wipe(&a); return (rc); } @@ -922,7 +903,7 @@ static int message_handler (BODY * a, STATE * s) if (a->encoding == ENCBASE64 || a->encoding == ENCQUOTEDPRINTABLE || a->encoding == ENCUUENCODED) { fstat (fileno (s->fpin), &st); - b = mutt_new_body (); + b = body_new(); b->length = (long) st.st_size; b->parts = mutt_parse_messageRFC822 (s->fpin, b); } @@ -946,7 +927,7 @@ static int message_handler (BODY * a, STATE * s) if (a->encoding == ENCBASE64 || a->encoding == ENCQUOTEDPRINTABLE || a->encoding == ENCUUENCODED) - mutt_free_body (&b); + body_list_wipe(&b); return (rc); } @@ -997,14 +978,12 @@ static int multipart_handler (BODY * a, STATE * s) if (a->encoding == ENCBASE64 || a->encoding == ENCQUOTEDPRINTABLE || a->encoding == ENCUUENCODED) { fstat (fileno (s->fpin), &st); - b = mutt_new_body (); + b = body_new(); b->length = (long) st.st_size; - b->parts = mutt_parse_multipart (s->fpin, - mutt_get_parameter ("boundary", - a->parameter), - (long) st.st_size, - ascii_strcasecmp ("digest", - a->subtype) == 0); + b->parts = mutt_parse_multipart(s->fpin, + parameter_getval(a->parameter, "boundary"), + (long)st.st_size, + !ascii_strcasecmp("digest", a->subtype)); } else b = a; @@ -1049,7 +1028,7 @@ static int multipart_handler (BODY * a, STATE * s) if (a->encoding == ENCBASE64 || a->encoding == ENCQUOTEDPRINTABLE || a->encoding == ENCUUENCODED) - mutt_free_body (&b); + body_list_wipe(&b); return (rc); } @@ -1100,10 +1079,9 @@ static int autoview_handler (BODY * a, STATE * s) mutt_copy_bytes (s->fpin, fpin, a->length); if (!piped) { - safe_fclose (&fpin); + m_fclose(&fpin); thepid = mutt_create_filter (command, NULL, &fpout, &fperr); - } - else { + } else { unlink (tempfile); fflush (fpin); rewind (fpin); @@ -1141,8 +1119,7 @@ static int autoview_handler (BODY * a, STATE * s) state_puts (buffer, s); } } - } - else { + } else { mutt_copy_stream (fpout, s->fpout); /* Check for stderr messages */ if (fgets (buffer, sizeof (buffer), fperr)) { @@ -1157,12 +1134,12 @@ static int autoview_handler (BODY * a, STATE * s) } bail: - safe_fclose (&fpout); - safe_fclose (&fperr); + m_fclose(&fpout); + m_fclose(&fperr); mutt_wait_filter (thepid); if (piped) - safe_fclose (&fpin); + m_fclose(&fpin); else mutt_unlink (tempfile); @@ -1179,7 +1156,7 @@ static int external_body_handler (BODY * b, STATE * s) const char *expiration; time_t expire; - access_type = mutt_get_parameter ("access-type", b->parameter); + access_type = parameter_getval(b->parameter, "access-type"); if (!access_type) { if (s->flags & M_DISPLAY) { state_mark_attach (s); @@ -1188,7 +1165,7 @@ static int external_body_handler (BODY * b, STATE * s) return (-1); } - expiration = mutt_get_parameter ("expiration", b->parameter); + expiration = parameter_getval(b->parameter, "expiration"); if (expiration) expire = mutt_parse_date (expiration, NULL); else @@ -1202,7 +1179,7 @@ static int external_body_handler (BODY * b, STATE * s) state_mark_attach (s); state_printf (s, _("[-- This %s/%s attachment "), TYPE (b->parts), b->parts->subtype); - length = mutt_get_parameter ("length", b->parameter); + length = parameter_getval(b->parameter, "length"); if (length) { mutt_pretty_size (pretty_size, sizeof (pretty_size), strtol (length, NULL, 10)); @@ -1236,8 +1213,7 @@ static int external_body_handler (BODY * b, STATE * s) (option (OPTWEED) ? (CH_WEED | CH_REORDER) : 0) | CH_DECODE, NULL); } - } - else { + } else { if (s->flags & M_DISPLAY) { state_mark_attach (s); state_printf (s, @@ -1259,20 +1235,19 @@ static int external_body_handler (BODY * b, STATE * s) void mutt_decode_attachment (BODY * b, STATE * s) { int istext = mutt_is_text_part (b); - iconv_t cd = (iconv_t) (-1); + iconv_t cd = MUTT_ICONV_ERROR; Quotebuf[0] = '\0'; if (istext) { if (s->flags & M_CHARCONV) { - const char *charset = mutt_get_parameter ("charset", b->parameter); + const char *charset = parameter_getval(b->parameter, "charset"); - if (!option (OPTSTRICTMIME) && !charset) - charset = mutt_get_first_charset (AssumedCharset); + if (!charset) + charset = charset_getfirst(AssumedCharset); if (charset && Charset) cd = mutt_iconv_open (Charset, charset, M_ICONV_HOOK_FROM); - } - else { + } else { if (b->file_charset) cd = mutt_iconv_open (Charset, b->file_charset, M_ICONV_HOOK_FROM); } @@ -1298,7 +1273,7 @@ void mutt_decode_attachment (BODY * b, STATE * s) break; } - if (cd != (iconv_t) (-1)) + if (cd != MUTT_ICONV_ERROR) iconv_close (cd); } @@ -1336,9 +1311,8 @@ int mutt_body_handler (BODY * b, STATE * s) if (mutt_is_application_pgp (b)) handler = crypt_pgp_application_pgp_handler; else - if (ascii_strcasecmp - ("flowed", mutt_get_parameter ("format", b->parameter)) == 0) - handler = rfc3676_handler; + if (!ascii_strcasecmp("flowed", parameter_getval(b->parameter, "format"))) + handler = rfc3676_handler; else plaintext = 1; } @@ -1348,7 +1322,7 @@ int mutt_body_handler (BODY * b, STATE * s) plaintext = 1; } else if (b->type == TYPEMESSAGE) { - if (mutt_is_message_type (b->type, b->subtype)) + if (mutt_is_message_type (b)) handler = message_handler; else if (!ascii_strcasecmp ("delivery-status", b->subtype)) plaintext = 1; @@ -1361,7 +1335,7 @@ int mutt_body_handler (BODY * b, STATE * s) if (ascii_strcasecmp ("alternative", b->subtype) == 0) handler = alternative_handler; else if (ascii_strcasecmp ("signed", b->subtype) == 0) { - p = mutt_get_parameter ("protocol", b->parameter); + p = parameter_getval(b->parameter, "protocol"); if (!p) mutt_error (_("Error: multipart/signed has no protocol.")); @@ -1370,7 +1344,7 @@ int mutt_body_handler (BODY * b, STATE * s) handler = mutt_signed_handler; } else if (m_strcasecmp("encrypted", b->subtype) == 0) { - p = mutt_get_parameter ("protocol", b->parameter); + p = parameter_getval(b->parameter, "protocol"); if (!p) mutt_error (_ @@ -1395,21 +1369,19 @@ int mutt_body_handler (BODY * b, STATE * s) fseeko (s->fpin, b->offset, 0); /* see if we need to decode this part before processing it */ - if (b->encoding == ENCBASE64 || b->encoding == ENCQUOTEDPRINTABLE || b->encoding == ENCUUENCODED || plaintext || mutt_is_text_part (b)) { /* text subtypes may - * require character - * set conversion even - * with 8bit encoding. - */ + if (b->encoding == ENCBASE64 || b->encoding == ENCQUOTEDPRINTABLE + || b->encoding == ENCUUENCODED || plaintext || mutt_is_text_part (b)) { + /* text subtypes may require character set conversion even with 8bit + encoding. */ int origType = b->type; char *savePrefix = NULL; if (!plaintext) { /* decode to a tempfile, saving the original destination */ fp = s->fpout; - mutt_mktemp (tempfile); - if ((s->fpout = safe_fopen (tempfile, "w")) == NULL) { + s->fpout = m_tempfile(tempfile, sizeof(tempfile), NONULL(Tempdir), NULL); + if (!s->fpout) { mutt_error _("Unable to open temporary file!"); - goto bail; } /* decoding the attachment changes the size and offset, so save a copy @@ -1425,16 +1397,16 @@ int mutt_body_handler (BODY * b, STATE * s) s->prefix = NULL; decode = 1; - } - else + } else { b->type = TYPETEXT; + } mutt_decode_attachment (b, s); if (decode) { b->length = ftello (s->fpout); b->offset = 0; - fclose (s->fpout); + m_fclose(&s->fpout); /* restore final destination and substitute the tempfile for input */ s->fpout = fp; @@ -1458,7 +1430,7 @@ int mutt_body_handler (BODY * b, STATE * s) b->offset = tmpoffset; /* restore the original source stream */ - fclose (s->fpin); + m_fclose(&s->fpin); s->fpin = fp; } }