X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=sendlib.c;h=8c3d68c87ee1bb39a74576bdd094408344726557;hp=cc2562d9c1c10fa80c38c3d5d893cc582cfe4907;hb=f3cbb9f51357972f6e74244494236a41dc4d84cd;hpb=8476307969a605bea67f6b702b0c1e7a52038bed diff --git a/sendlib.c b/sendlib.c index cc2562d..8c3d68c 100644 --- a/sendlib.c +++ b/sendlib.c @@ -7,8 +7,6 @@ * please see the file GPL in the top level source directory. */ -#define _SENDLIB_C 1 - #include #include @@ -35,7 +33,7 @@ #endif /* USE_LIBESMTP */ #ifdef USE_NNTP -#include +#include #endif #ifdef HAVE_SYSEXITS_H @@ -44,17 +42,6 @@ #define EX_OK 0 #endif -/* If you are debugging this file, comment out the following line. */ -/*#define NDEBUG*/ - -#ifdef NDEBUG -#define assert(x) -#else -#include -#endif - -#define DISPOSITION(X) X==DISPATTACH?"attachment":"inline" - static void transform_to_7bit (BODY * a, FILE * fpin); static void encode_quoted (fgetconv_t * fc, FILE * fout, int istext) @@ -244,7 +231,8 @@ static void encode_base64 (fgetconv_t * fc, FILE * fout, int istext) fputc ('\n', fout); } -static void encode_8bit (fgetconv_t * fc, FILE * fout, int istext) +static void encode_8bit (fgetconv_t * fc, FILE * fout, + int istext __attribute__ ((unused))) { int ch; @@ -314,6 +302,7 @@ int mutt_write_mime_header (BODY * a, FILE * f) if (a->description) fprintf (f, "Content-Description: %s\n", a->description); +#define DISPOSITION(X) X==DISPATTACH?"attachment":"inline" fprintf (f, "Content-Disposition: %s", DISPOSITION (a->disposition)); if (a->use_disp) { @@ -407,7 +396,7 @@ int mutt_write_mime_body (BODY * a, FILE * f) #undef write_as_text_part fgetconv_close (&fc); - fclose (fpin); + m_fclose(&fpin); return (ferror (f) ? -1 : 0); } @@ -588,10 +577,7 @@ static ssize_t convert_file_to (FILE * file, const char *fromcode, ib = bufi; ob = bufu, obl = sizeof (bufu); n = my_iconv(cd1, ibl ? &ib : 0, &ibl, &ob, &obl); - assert (n == -1 || !n); if (n == -1 && ((errno != EINVAL && errno != E2BIG) || ib == bufi)) { - assert (errno == EILSEQ || - (errno == EINVAL && ib == bufi && ibl < ssizeof (bufi))); ret = -1; break; } @@ -791,7 +777,7 @@ CONTENT *mutt_get_content_info (const char *fname, BODY * b) } b->file_charset = fromcode; p_delete(&tocode); - safe_fclose (&fp); + m_fclose(&fp); return info; } } @@ -801,7 +787,7 @@ CONTENT *mutt_get_content_info (const char *fname, BODY * b) update_content_info (info, &state, buffer, r); update_content_info (info, &state, 0, 0); - safe_fclose (&fp); + m_fclose(&fp); if (b != NULL && b->type == TYPETEXT && (!b->noconv && !b->force_charset)) parameter_setval(&b->parameter, "charset", @@ -900,7 +886,7 @@ int mutt_lookup_mime_type (BODY * att, const char *path) p = NULL; } } - fclose (f); + m_fclose(&f); } } @@ -933,14 +919,14 @@ void mutt_message_to_7bit (BODY * a, FILE * fp) a->offset = 0; if (stat (a->filename, &sb) == -1) { mutt_perror ("stat"); - fclose (fpin); + m_fclose(&fpin); } a->length = sb.st_size; } - mutt_mktemp (temp); - if (!(fpout = safe_fopen (temp, "w+"))) { - mutt_perror ("fopen"); + fpout = m_tempfile(temp, sizeof(temp), NONULL(Tempdir), NULL); + if (!fpout) { + mutt_error(_("Could not create temporary file")); goto cleanup; } @@ -961,9 +947,9 @@ cleanup: p_delete(&line); if (fpin && !fp) - fclose (fpin); + m_fclose(&fpin); if (fpout) - fclose (fpout); + m_fclose(&fpout); else return; @@ -1003,14 +989,14 @@ static void transform_to_7bit (BODY * a, FILE * fpin) a->noconv = 1; a->force_charset = 1; - mutt_mktemp (buff); - if ((s.fpout = safe_fopen (buff, "w")) == NULL) { - mutt_perror ("fopen"); + s.fpout = m_tempfile(buff, sizeof(buff), NONULL(Tempdir), NULL); + if (!s.fpout) { + mutt_error(_("Could not create temporary file")); return; } s.fpin = fpin; mutt_decode_attachment (a, &s); - fclose (s.fpout); + m_fclose(&s.fpout); a->d_filename = a->filename; a->filename = m_strdup(buff); a->unlink = 1; @@ -1127,8 +1113,8 @@ BODY *mutt_make_message_attach (CONTEXT * ctx, HEADER * hdr, int attach_msg) return (NULL); } - mutt_mktemp (buffer); - if ((fp = safe_fopen (buffer, "w+")) == NULL) + fp = m_tempfile(buffer, sizeof(buffer), NONULL(Tempdir), NULL); + if (!fp) return NULL; body = body_new(); @@ -1182,7 +1168,7 @@ BODY *mutt_make_message_attach (CONTEXT * ctx, HEADER * hdr, int attach_msg) mutt_update_encoding (body); body->parts = body->hdr->content; - fclose (fp); + m_fclose(&fp); return (body); } @@ -1322,31 +1308,22 @@ void mutt_write_address_list (address_t * adr, FILE * fp, int linelen, fputc ('\n', fp); } -/* arbitrary number of elements to grow the array by */ -#define REF_INC 16 - -#define TrimRef 10 - /* need to write the list in reverse because they are stored in reverse order * when parsed to speed up threading */ -void mutt_write_references (string_list_t * r, FILE * f) +void mutt_write_references(string_list_t *r, FILE *f) { - string_list_t **ref = NULL; - int refcnt = 0, refmax = 0; - - for (; (TrimRef == 0 || refcnt < TrimRef) && r; r = r->next) { - if (refcnt == refmax) - p_realloc(&ref, refmax += REF_INC); - ref[refcnt++] = r; - } + string_list_t *refs[10]; + int i; - while (refcnt-- > 0) { - fputc (' ', f); - fputs (ref[refcnt]->data, f); - } + p_clear(refs, countof(refs)); + for (i = 0; i < countof(refs) && r; r = r->next) { + refs[i++] = r; + } - p_delete(&ref); + while (i-- > 0) { + fprintf(f, " %s", refs[i]->data); + } } static int edit_header(int mode, const char *s) @@ -1557,7 +1534,7 @@ static void encode_headers (string_list_t * h) rfc2047_encode_string (&tmp); p_realloc(&h->data, m_strlen(h->data) + 2 + m_strlen(tmp) + 1); - sprintf (h->data + i, ": %s", NONULL (tmp)); /* __SPRINTF_CHECKED__ */ + sprintf (h->data + i, ": %s", NONULL (tmp)); p_delete(&tmp); } @@ -1586,12 +1563,6 @@ const char *mutt_fqdn (short may_hide_host) return p; } -/* normalized character (we're stricter than RFC2822, 3.6.4) */ -static char mutt_normalized_char(char c) -{ - return (isalnum(c) || strchr(".!#$%&'*+-/=?^_`{|}~", c)) ? c : '.'; -} - static void mutt_gen_localpart(char *buf, unsigned int len, const char *fmt) { #define APPEND_FMT(fmt, arg) \ @@ -1619,7 +1590,8 @@ static void mutt_gen_localpart(char *buf, unsigned int len, const char *fmt) int c = *fmt++; if (c != '%') { - APPEND_BYTE(mutt_normalized_char(c)); + /* normalized character (we're stricter than RFC2822, 3.6.4) */ + APPEND_BYTE((isalnum(c) || strchr(".!#$%&'*+-/=?^_`{|}~", c)) ? c : '.'); continue; } @@ -1671,7 +1643,6 @@ static void mutt_gen_localpart(char *buf, unsigned int len, const char *fmt) break; default: /* invalid formats are replaced by '.' */ APPEND_BYTE('.'); - m_strncat(buf, len, ".", 1); } } @@ -1683,23 +1654,19 @@ static void mutt_gen_localpart(char *buf, unsigned int len, const char *fmt) static char *mutt_gen_msgid (void) { - char buf[SHORT_STRING]; - char localpart[SHORT_STRING]; - unsigned int localpart_length; - const char *fqdn; + char buf[SHORT_STRING]; + char localpart[SHORT_STRING]; + const char *fqdn; - if (!(fqdn = mutt_fqdn (0))) - fqdn = NONULL (Hostname); + if (!(fqdn = mutt_fqdn(0))) + fqdn = NONULL(Hostname); - localpart_length = sizeof (buf) - m_strlen(fqdn) - 4; /* the 4 characters are '<', '@', '>' and '\0' */ - - mutt_gen_localpart (localpart, localpart_length, MsgIdFormat); - - snprintf (buf, sizeof (buf), "<%s@%s>", localpart, fqdn); - return (m_strdup(buf)); + mutt_gen_localpart(localpart, sizeof(localpart), MsgIdFormat); + snprintf(buf, sizeof(buf), "<%s@%s>", localpart, fqdn); + return m_strdup(buf); } -static RETSIGTYPE alarm_handler (int sig) +static RETSIGTYPE alarm_handler (int sig __attribute__ ((unused))) { SigAlrm = 1; } @@ -1881,7 +1848,7 @@ static int mutt_invoke_sendmail (address_t * from, /* the sender */ mutt_FormatString (cmd, sizeof (cmd), NONULL (Inews), nntp_format_str, 0, 0); - if (!*cmd) { + if (m_strisempty(cmd)) { i = nntp_post (msg); unlink (msg); return i; @@ -2087,8 +2054,8 @@ static int _mutt_bounce_message (FILE * fp, HEADER * h, address_t * to, if (!fp) fp = msg->fp; - mutt_mktemp (tempfile); - if ((f = safe_fopen (tempfile, "w")) != NULL) { + f = m_tempfile(tempfile, sizeof(tempfile), NONULL(Tempdir), NULL); + if (f) { int ch_flags = CH_XMIT | CH_NONEWLINE | CH_NOQFROM; if (!option (OPTBOUNCEDELIVERED)) @@ -2104,10 +2071,10 @@ static int _mutt_bounce_message (FILE * fp, HEADER * h, address_t * to, mutt_copy_header (fp, h, f, ch_flags, NULL); fputc ('\n', f); mutt_copy_bytes (fp, f, h->content->length); - fclose (f); + m_fclose(&f); - ret = mutt_invoke_mta (env_from, to, NULL, NULL, tempfile, - h->content->encoding == ENC8BIT); + ret = mutt_invoke_mta(env_from, to, NULL, NULL, tempfile, + h->content->encoding == ENC8BIT); } if (msg) @@ -2179,11 +2146,11 @@ int mutt_write_fcc (const char *path, HEADER * hdr, const char *msgid, * the message body begins with "From " */ if (f.magic == M_MMDF || f.magic == M_MBOX) { - mutt_mktemp (tempfile); - if ((tempfp = safe_fopen (tempfile, "w+")) == NULL) { - mutt_perror (tempfile); + tempfp = m_tempfile(tempfile, sizeof(tempfile), NONULL(Tempdir), NULL); + if (!tempfp) { + mutt_error(_("Could not create temporary file")); mx_close_mailbox (&f, NULL); - return (-1); + return -1; } } @@ -2250,11 +2217,9 @@ int mutt_write_fcc (const char *path, HEADER * hdr, const char *msgid, fputc ('\n', msg->fp); } -#ifdef MIXMASTER /* (postponement) if the mail is to be sent through a mixmaster * chain, save that information */ - if (post && hdr->chain && hdr->chain) { string_list_t *p; @@ -2264,7 +2229,6 @@ int mutt_write_fcc (const char *path, HEADER * hdr, const char *msgid, fputc ('\n', msg->fp); } -#endif if (tempfp) { char sasha[LONG_STRING]; @@ -2284,7 +2248,7 @@ int mutt_write_fcc (const char *path, HEADER * hdr, const char *msgid, fflush (tempfp); if (ferror (tempfp)) { - fclose (tempfp); + m_fclose(&tempfp); unlink (tempfile); mx_commit_message (msg, &f); /* XXX - really? */ mx_close_message (&msg); @@ -2302,7 +2266,7 @@ int mutt_write_fcc (const char *path, HEADER * hdr, const char *msgid, /* copy the body and clean up */ rewind (tempfp); r = mutt_copy_stream (tempfp, msg->fp); - if (fclose (tempfp) != 0) + if (m_fclose(&tempfp) != 0) r = -1; /* if there was an error, leave the temp version */ if (!r)