use more ad-hoc list handling function, and avoid to muck with ->next
[apps/madmutt.git] / sendlib.c
index 5b9b56f..e92b825 100644 (file)
--- a/sendlib.c
+++ b/sendlib.c
@@ -29,7 +29,6 @@
 #include <lib-lib/str.h>
 #include <lib-lib/macros.h>
 #include <lib-lib/file.h>
-#include <lib-lib/debug.h>
 
 #include <lib-sys/exit.h>
 #include <lib-sys/mutt_signal.h>
@@ -77,7 +76,7 @@ static char MsgIdPfx = 'A';
 
 static void transform_to_7bit (BODY * a, FILE * fpin);
 
-static void encode_quoted (FGETCONV * fc, FILE * fout, int istext)
+static void encode_quoted (fgetconv_t * fc, FILE * fout, int istext)
 {
   int c, linelen = 0;
   char line[77], savechar;
@@ -248,7 +247,7 @@ static void b64_putc (char c, FILE * fout)
 }
 
 
-static void encode_base64 (FGETCONV * fc, FILE * fout, int istext)
+static void encode_base64 (fgetconv_t * fc, FILE * fout, int istext)
 {
   int ch, ch1 = EOF;
 
@@ -264,7 +263,7 @@ static void encode_base64 (FGETCONV * fc, FILE * fout, int istext)
   fputc ('\n', fout);
 }
 
-static void encode_8bit (FGETCONV * fc, FILE * fout, int istext)
+static void encode_8bit (fgetconv_t * fc, FILE * fout, int istext)
 {
   int ch;
 
@@ -275,7 +274,6 @@ static void encode_8bit (FGETCONV * fc, FILE * fout, int istext)
 
 int mutt_write_mime_header (BODY * a, FILE * f)
 {
-  PARAMETER *p;
   char buffer[STRING];
   char *t;
   char *fn;
@@ -286,6 +284,8 @@ int mutt_write_mime_header (BODY * a, FILE * f)
   fprintf (f, "Content-Type: %s/%s", TYPE (a), a->subtype);
 
   if (a->parameter) {
+    PARAMETER *p;
+
     len = 25 + m_strlen(a->subtype);        /* approximate len. of content-type */
 
     for (p = a->parameter; p; p = p->next) {
@@ -374,12 +374,11 @@ int mutt_write_mime_body (BODY * a, FILE * f)
   char send_charset[SHORT_STRING];
   FILE *fpin;
   BODY *t;
-  FGETCONV *fc;
+  fgetconv_t *fc;
 
   if (a->type == TYPEMULTIPART) {
     /* First, find the boundary to use */
     if (!(p = mutt_get_parameter ("boundary", a->parameter))) {
-      debug_print (1, ("no boundary parameter found!\n"));
       mutt_error _("No boundary parameter found! [report this error]");
 
       return (-1);
@@ -405,7 +404,6 @@ int mutt_write_mime_body (BODY * a, FILE * f)
   }
 
   if ((fpin = fopen (a->filename, "r")) == NULL) {
-    debug_print (1, ("%s no longer exists!\n", a->filename));
     mutt_error (_("%s no longer exists!"), a->filename);
     return -1;
   }
@@ -601,7 +599,7 @@ static ssize_t convert_file_to (FILE * file, const char *fromcode,
   ssize_t *score;
 
   cd1 = mutt_iconv_open ("UTF-8", fromcode, 0);
-  if (cd1 == (iconv_t) (-1))
+  if (cd1 == MUTT_ICONV_ERROR)
     return -1;
 
   cd = p_new(iconv_t, ncodes);
@@ -614,7 +612,7 @@ static ssize_t convert_file_to (FILE * file, const char *fromcode,
       cd[i] = mutt_iconv_open (tocodes[i], "UTF-8", 0);
     else
       /* Special case for conversion to UTF-8 */
-      cd[i] = (iconv_t) (-1), score[i] = -1;
+      cd[i] = MUTT_ICONV_ERROR, score[i] = -1;
 
   rewind (file);
   ibl = 0;
@@ -628,7 +626,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 || ICONV_NONTRANS);
+    assert (n == -1 || !n);
     if (n == -1 &&
         ((errno != EINVAL && errno != E2BIG) || ib == bufi)) {
       assert (errno == EILSEQ ||
@@ -640,7 +638,7 @@ static ssize_t convert_file_to (FILE * file, const char *fromcode,
 
     /* Convert from UTF-8 */
     for (i = 0; i < ncodes; i++)
-      if (cd[i] != (iconv_t) (-1) && score[i] != -1) {
+      if (cd[i] != MUTT_ICONV_ERROR && score[i] != -1) {
         ub = bufu, ubl = ubl1;
         ob = bufo, obl = sizeof (bufo);
         n = my_iconv(cd[i], (ibl || ubl) ? &ub : 0, &ubl, &ob, &obl);
@@ -654,7 +652,7 @@ static ssize_t convert_file_to (FILE * file, const char *fromcode,
           update_content_info (&infos[i], &states[i], bufo, ob - bufo);
         }
       }
-      else if (cd[i] == (iconv_t) (-1) && score[i] == -1)
+      else if (cd[i] == MUTT_ICONV_ERROR && score[i] == -1)
         /* Special case for conversion to UTF-8 */
         update_content_info (&infos[i], &states[i], bufu, ubl1);
 
@@ -671,13 +669,13 @@ static ssize_t convert_file_to (FILE * file, const char *fromcode,
     /* Find best score */
     ret = -1;
     for (i = 0; i < ncodes; i++) {
-      if (cd[i] == (iconv_t) (-1) && score[i] == -1) {
+      if (cd[i] == MUTT_ICONV_ERROR && score[i] == -1) {
         /* Special case for conversion to UTF-8 */
         *tocode = i;
         ret = 0;
         break;
       }
-      else if (cd[i] == (iconv_t) (-1) || score[i] == -1)
+      else if (cd[i] == MUTT_ICONV_ERROR || score[i] == -1)
         continue;
       else if (ret == -1 || score[i] < ret) {
         *tocode = i;
@@ -693,7 +691,7 @@ static ssize_t convert_file_to (FILE * file, const char *fromcode,
   }
 
   for (i = 0; i < ncodes; i++)
-    if (cd[i] != (iconv_t) (-1))
+    if (cd[i] != MUTT_ICONV_ERROR)
       iconv_close (cd[i]);
 
   iconv_close (cd1);
@@ -815,7 +813,6 @@ CONTENT *mutt_get_content_info (const char *fname, BODY * b)
   }
 
   if ((fp = fopen (fname, "r")) == NULL) {
-    debug_print (1, ("%s: %s (errno %d).\n", fname, strerror (errno), errno));
     return (NULL);
   }
 
@@ -830,7 +827,7 @@ CONTENT *mutt_get_content_info (const char *fname, BODY * b)
         convert_file_from_to (fp, fchs, chs ? chs : SendCharset,
                               &fromcode, &tocode, info) != -1) {
       if (!chs) {
-        mutt_canonical_charset (chsbuf, sizeof (chsbuf), tocode);
+        charset_canonicalize (chsbuf, sizeof (chsbuf), tocode);
         mutt_set_parameter ("charset", chsbuf, &b->parameter);
       }
       b->file_charset = fromcode;
@@ -850,7 +847,7 @@ CONTENT *mutt_get_content_info (const char *fname, BODY * b)
   if (b != NULL && b->type == TYPETEXT && (!b->noconv && !b->force_charset))
     mutt_set_parameter ("charset", (!info->hibin ? "us-ascii" :
                                     Charset
-                                    && !mutt_is_us_ascii (Charset) ? Charset :
+                                    && !charset_is_us_ascii (Charset) ? Charset :
                                     "unknown-8bit"), &b->parameter);
 
   return info;
@@ -899,7 +896,6 @@ int mutt_lookup_mime_type (BODY * att, const char *path)
       m_strcpy(buf, sizeof(buf), SYSCONFDIR "/mime.types");
       break;
     default:
-      debug_print (1, ("Internal error, count = %d.\n", count));
       goto bye;                 /* shouldn't happen */
     }
 
@@ -1141,7 +1137,7 @@ char *mutt_get_body_charset (char *d, ssize_t dlen, BODY * b)
     p = mutt_get_parameter ("charset", b->parameter);
 
   if (p)
-    mutt_canonical_charset (d, dlen, NONULL (p));
+    charset_canonicalize (d, dlen, NONULL (p));
   else
     m_strcpy(d, dlen, "us-ascii");
 
@@ -1156,7 +1152,7 @@ void mutt_update_encoding (BODY * a)
   char chsbuff[STRING];
 
   /* override noconv when it's us-ascii */
-  if (mutt_is_us_ascii (mutt_get_body_charset (chsbuff, sizeof (chsbuff), a)))
+  if (charset_is_us_ascii (mutt_get_body_charset (chsbuff, sizeof (chsbuff), a)))
     a->noconv = 0;
 
   if (!a->force_charset && !a->noconv)
@@ -2292,8 +2288,6 @@ address_t *mutt_remove_duplicates (address_t * addr)
     }
 
     if (dup) {
-      debug_print (2, ("Removing %s\n", addr->mailbox));
-
       *last = addr->next;
 
       addr->next = NULL;
@@ -2337,7 +2331,6 @@ int mutt_write_fcc (const char *path, HEADER * hdr, const char *msgid,
     set_noconv_flags (hdr->content, 1);
 
   if (mx_open_mailbox (path, M_APPEND | M_QUIET, &f) == NULL) {
-    debug_print (1, ("unable to open mailbox %s in append-mode, aborting.\n", path));
     return (-1);
   }
 
@@ -2450,7 +2443,6 @@ int mutt_write_fcc (const char *path, HEADER * hdr, const char *msgid,
 
     fflush (tempfp);
     if (ferror (tempfp)) {
-      debug_print (1, ("%s: write failed.\n", tempfile));
       fclose (tempfp);
       unlink (tempfile);
       mx_commit_message (msg, &f);      /* XXX - really? */