Nico Golde:
[apps/madmutt.git] / parse.c
diff --git a/parse.c b/parse.c
index 64b22f4..ee8d70f 100644 (file)
--- a/parse.c
+++ b/parse.c
@@ -12,7 +12,7 @@
 #endif
 
 #include "mutt.h"
-#include "mailbox.h"
+#include "mx.h"
 #include "mime.h"
 #include "rfc2047.h"
 #include "rfc2231.h"
@@ -23,6 +23,7 @@
 #include "lib/intl.h"
 #include "lib/str.h"
 #include "lib/rx.h"
+#include "lib/debug.h"
 
 #include <string.h>
 #include <ctype.h>
@@ -168,12 +169,11 @@ static PARAMETER *parse_parameters (const char *s)
   const char *p;
   size_t i;
 
-  dprint (2, (debugfile, "parse_parameters: `%s'\n", s));
+  debug_print (2, ("`%s'\n", s));
 
   while (*s) {
     if ((p = strpbrk (s, "=;")) == NULL) {
-      dprint (1,
-              (debugfile, "parse_parameters: malformed parameter: %s\n", s));
+      debug_print (1, ("malformed parameter: %s\n", s));
       goto bail;
     }
 
@@ -233,8 +233,7 @@ static PARAMETER *parse_parameters (const char *s)
 
       new->value = safe_strdup (buffer);
 
-      dprint (2, (debugfile, "parse_parameter: `%s' = `%s'\n",
-                  new->attribute ? new->attribute : "",
+      debug_print (2, ("`%s' = `%s'\n", new->attribute ? new->attribute : "", 
                   new->value ? new->value : ""));
 
       /* Add this parameter to the list */
@@ -246,9 +245,7 @@ static PARAMETER *parse_parameters (const char *s)
         head = cur = new;
     }
     else {
-      dprint (1,
-              (debugfile, "parse_parameters(): parameter with no value: %s\n",
-               s));
+      debug_print (1, ("parameter with no value: %s\n", s));
       s = p;
     }
 
@@ -397,7 +394,7 @@ static void parse_content_disposition (char *s, BODY * ct)
     if ((s =
          mutt_get_parameter ("filename",
                              (parms = parse_parameters (s)))) != 0)
-      mutt_str_replace (&ct->filename, s);
+      str_replace (&ct->filename, s);
     if ((s = mutt_get_parameter ("name", parms)) != 0)
       ct->form_name = safe_strdup (s);
     mutt_free_parameter (&parms);
@@ -431,16 +428,12 @@ BODY *mutt_read_mime_header (FILE * fp, int digest)
       c++;
       SKIPWS (c);
       if (!*c) {
-        dprint (1,
-                (debugfile,
-                 "mutt_read_mime_header(): skipping empty header field: %s\n",
-                 line));
+        debug_print (1, ("skipping empty header field: %s\n", line));
         continue;
       }
     }
     else {
-      dprint (1,
-              (debugfile, "read_mime_header: bogus MIME header: %s\n", line));
+      debug_print (1, ("bogus MIME header: %s\n", line));
       break;
     }
 
@@ -452,7 +445,7 @@ BODY *mutt_read_mime_header (FILE * fp, int digest)
       else if (!ascii_strcasecmp ("disposition", line + 8))
         parse_content_disposition (c, p);
       else if (!ascii_strcasecmp ("description", line + 8)) {
-        mutt_str_replace (&p->description, c);
+        str_replace (&p->description, c);
         rfc2047_decode (&p->description);
       }
     }
@@ -465,7 +458,7 @@ BODY *mutt_read_mime_header (FILE * fp, int digest)
       else if (!ascii_strcasecmp ("content-lines", line + 6))
         mutt_set_parameter ("content-lines", c, &(p->parameter));
       else if (!ascii_strcasecmp ("data-description", line + 6)) {
-        mutt_str_replace (&p->description, c);
+        str_replace (&p->description, c);
         rfc2047_decode (&p->description);
       }
     }
@@ -521,7 +514,7 @@ void mutt_parse_part (FILE * fp, BODY * b)
   /* try to recover from parsing error */
   if (!b->parts) {
     b->type = TYPETEXT;
-    mutt_str_replace (&b->subtype, "plain");
+    str_replace (&b->subtype, "plain");
   }
 }
 
@@ -596,7 +589,7 @@ BODY *mutt_parse_multipart (FILE * fp, const char *boundary, long end_off,
     crlf = (len > 1 && buffer[len - 2] == '\r') ? 1 : 0;
 
     if (buffer[0] == '-' && buffer[1] == '-' &&
-        mutt_strncmp (buffer + 2, boundary, blen) == 0) {
+        safe_strncmp (buffer + 2, boundary, blen) == 0) {
       if (last) {
         last->length = ftell (fp) - last->offset - len - 1 - crlf;
         if (last->parts && last->parts->length == 0)
@@ -836,9 +829,7 @@ time_t mutt_parse_date (const char *s, HEADER * h)
       else if (sscanf (t, "%d:%d", &hour, &min) == 2)
         sec = 0;
       else {
-        dprint (1,
-                (debugfile, "parse_date: could not process time format: %s\n",
-                 t));
+        debug_print (1, ("could not process time format: %s\n", t));
         return (-1);
       }
       tm.tm_hour = hour;
@@ -898,9 +889,7 @@ time_t mutt_parse_date (const char *s, HEADER * h)
   }
 
   if (count < 4) {              /* don't check for missing timezone */
-    dprint (1,
-            (debugfile,
-             "parse_date(): error parsing date format, using received time\n"));
+    debug_print (1, ("error parsing date format, using received time\n"));
     return (-1);
   }
 
@@ -1004,7 +993,7 @@ int mutt_parse_rfc822_line (ENVELOPE * e, HEADER * hdr, char *line, char *p,
       }
       else if (ascii_strcasecmp (line + 8, "description") == 0) {
         if (hdr) {
-          mutt_str_replace (&hdr->content->description, p);
+          str_replace (&hdr->content->description, p);
           rfc2047_decode (&hdr->content->description);
         }
         matched = 1;
@@ -1019,7 +1008,7 @@ int mutt_parse_rfc822_line (ENVELOPE * e, HEADER * hdr, char *line, char *p,
 
   case 'd':
     if (!ascii_strcasecmp ("ate", line + 1)) {
-      mutt_str_replace (&e->date, p);
+      str_replace (&e->date, p);
       if (hdr)
         hdr->date_sent = mutt_parse_date (p, hdr);
       matched = 1;
@@ -1046,10 +1035,10 @@ int mutt_parse_rfc822_line (ENVELOPE * e, HEADER * hdr, char *line, char *p,
       matched = 1;
     }
 #ifdef USE_NNTP
-    else if (!mutt_strcasecmp (line + 1, "ollowup-to")) {
+    else if (!safe_strcasecmp (line + 1, "ollowup-to")) {
       if (!e->followup_to) {
-        mutt_remove_trailing_ws (p);
-        e->followup_to = safe_strdup (mutt_skip_whitespace (p));
+        str_skip_trailws (p);
+        e->followup_to = safe_strdup (str_skip_initws (p));
       }
       matched = 1;
     }
@@ -1092,7 +1081,7 @@ int mutt_parse_rfc822_line (ENVELOPE * e, HEADER * hdr, char *line, char *p,
           /* Take the first mailto URL */
           if (url_check_scheme (beg) == U_MAILTO) {
             FREE (&e->list_post);
-            e->list_post = mutt_substrdup (beg, end);
+            e->list_post = str_substrdup (beg, end);
             break;
           }
         }
@@ -1129,10 +1118,10 @@ int mutt_parse_rfc822_line (ENVELOPE * e, HEADER * hdr, char *line, char *p,
 
 #ifdef USE_NNTP
   case 'n':
-    if (!mutt_strcasecmp (line + 1, "ewsgroups")) {
+    if (!safe_strcasecmp (line + 1, "ewsgroups")) {
       FREE (&e->newsgroups);
-      mutt_remove_trailing_ws (p);
-      e->newsgroups = safe_strdup (mutt_skip_whitespace (p));
+      str_skip_trailws (p);
+      e->newsgroups = safe_strdup (str_skip_initws (p));
       matched = 1;
     }
     break;
@@ -1140,8 +1129,8 @@ int mutt_parse_rfc822_line (ENVELOPE * e, HEADER * hdr, char *line, char *p,
 
   case 'o':
     /* field `Organization:' saves only for pager! */
-    if (!mutt_strcasecmp (line + 1, "rganization")) {
-      if (!e->organization && mutt_strcasecmp (p, "unknown"))
+    if (!safe_strcasecmp (line + 1, "rganization")) {
+      if (!e->organization && safe_strcasecmp (p, "unknown"))
         e->organization = safe_strdup (p);
     }
     break;
@@ -1238,12 +1227,12 @@ int mutt_parse_rfc822_line (ENVELOPE * e, HEADER * hdr, char *line, char *p,
       matched = 1;
     }
 #ifdef USE_NNTP
-    else if (!mutt_strcasecmp (line + 1, "-comment-to")) {
+    else if (!safe_strcasecmp (line + 1, "-comment-to")) {
       if (!e->x_comment_to)
         e->x_comment_to = safe_strdup (p);
       matched = 1;
     }
-    else if (!mutt_strcasecmp (line + 1, "ref")) {
+    else if (!safe_strcasecmp (line + 1, "ref")) {
       if (!e->xref)
         e->xref = safe_strdup (p);
       matched = 1;
@@ -1335,7 +1324,7 @@ ENVELOPE *mutt_read_rfc822_header (FILE * f, HEADER * hdr, short user_hdrs,
       time_t t;
 
       /* some bogus MTAs will quote the original "From " line */
-      if (mutt_strncmp (">From ", line, 6) == 0)
+      if (safe_strncmp (">From ", line, 6) == 0)
         continue;               /* just ignore */
       else if (is_from (line, return_path, sizeof (return_path), &t)) {
         /* MH somtimes has the From_ line in the middle of the header! */
@@ -1380,7 +1369,7 @@ ENVELOPE *mutt_read_rfc822_header (FILE * f, HEADER * hdr, short user_hdrs,
         }
 
         if (e->spam && e->spam->data)
-          dprint (5, (debugfile, "p822: spam = %s\n", e->spam->data));
+          debug_print (5, ("spam = %s\n", e->spam->data));
       }
     }
 
@@ -1424,9 +1413,7 @@ ENVELOPE *mutt_read_rfc822_header (FILE * f, HEADER * hdr, short user_hdrs,
 
     /* check for missing or invalid date */
     if (hdr->date_sent <= 0) {
-      dprint (1,
-              (debugfile,
-               "read_rfc822_header(): no date found, using received time from msg separator\n"));
+      debug_print (1, ("no date found, using received time from msg separator\n"));
       hdr->date_sent = hdr->received;
     }
   }