Rocco Rutte:
[apps/madmutt.git] / parse.c
diff --git a/parse.c b/parse.c
index 7cb195f..ea5c9b8 100644 (file)
--- a/parse.c
+++ b/parse.c
 #endif
 
 #include "mutt.h"
+#include "buffer.h"
+#include "enter.h"
+#include "ascii.h"
+#include "recvattach.h"
 #include "mx.h"
 #include "mime.h"
 #include "rfc2047.h"
@@ -34,7 +38,7 @@
  * lines.  ``line'' must point to a dynamically allocated string; it is
  * increased if more space is required to fit the whole line.
  */
-static char *read_rfc822_line (FILE * f, char *line, size_t * linelen)
+char *mutt_read_rfc822_line (FILE * f, char *line, size_t * linelen)
 {
   char *buf = line;
   char ch;
@@ -72,7 +76,7 @@ static char *read_rfc822_line (FILE * f, char *line, size_t * linelen)
     if (*linelen < offset + STRING) {
       /* grow the buffer */
       *linelen += STRING;
-      safe_realloc (&line, *linelen);
+      mem_realloc (&line, *linelen);
       buf = line + offset;
     }
   }
@@ -108,7 +112,7 @@ LIST *mutt_parse_references (char *s, int in_reply_to)
     else if (o) {
       m = str_len (s);
       if (s[m - 1] == '>') {
-        new = safe_malloc (sizeof (char) * (n + m + 1));
+        new = mem_malloc (sizeof (char) * (n + m + 1));
         strcpy (new, o);        /* __STRCPY_CHECKED__ */
         strcpy (new + n, s);    /* __STRCPY_CHECKED__ */
       }
@@ -122,9 +126,9 @@ LIST *mutt_parse_references (char *s, int in_reply_to)
        */
       if (!(at = strchr (new, '@')) || strchr (at + 1, '@')
           || (in_reply_to && at - new <= 8))
-        FREE (&new);
+        mem_free (&new);
       else {
-        t = (LIST *) safe_malloc (sizeof (LIST));
+        t = (LIST *) mem_malloc (sizeof (LIST));
         t->data = new;
         t->next = lst;
         lst = t;
@@ -183,7 +187,7 @@ static PARAMETER *parse_parameters (const char *s)
 
       new = mutt_new_parameter ();
 
-      new->attribute = safe_malloc (i + 1);
+      new->attribute = mem_malloc (i + 1);
       memcpy (new->attribute, s, i);
       new->attribute[i] = 0;
 
@@ -299,7 +303,7 @@ void mutt_parse_content_type (char *s, BODY * ct)
   char *pc;
   char *subtype;
 
-  FREE (&ct->subtype);
+  mem_free (&ct->subtype);
   mutt_free_parameter (&ct->parameter);
 
   /* First extract any existing parameters */
@@ -412,7 +416,7 @@ BODY *mutt_read_mime_header (FILE * fp, int digest)
 {
   BODY *p = mutt_new_body ();
   char *c;
-  char *line = safe_malloc (LONG_STRING);
+  char *line = mem_malloc (LONG_STRING);
   size_t linelen = LONG_STRING;
 
   p->hdr_offset = ftell (fp);
@@ -421,7 +425,7 @@ BODY *mutt_read_mime_header (FILE * fp, int digest)
   p->type = digest ? TYPEMESSAGE : TYPETEXT;
   p->disposition = DISPINLINE;
 
-  while (*(line = read_rfc822_line (fp, line, &linelen)) != 0) {
+  while (*(line = mutt_read_rfc822_line (fp, line, &linelen)) != 0) {
     /* Find the value of the current header */
     if ((c = strchr (line, ':'))) {
       *c = 0;
@@ -470,7 +474,7 @@ BODY *mutt_read_mime_header (FILE * fp, int digest)
   else if (p->type == TYPEMESSAGE && !p->subtype)
     p->subtype = str_dup ("rfc822");
 
-  FREE (&line);
+  mem_free (&line);
 
   return (p);
 }
@@ -912,7 +916,7 @@ static char *extract_message_id (const char *s)
   if ((s = strchr (s, '<')) == NULL || (p = strchr (s, '>')) == NULL)
     return (NULL);
   l = (size_t) (p - s) + 1;
-  r = safe_malloc (l + 1);
+  r = mem_malloc (l + 1);
   memcpy (r, s, l);
   r[l] = 0;
   return (r);
@@ -1030,7 +1034,7 @@ int mutt_parse_rfc822_line (ENVELOPE * e, HEADER * hdr, char *line, char *p,
        * bothered me for _years_ */
       if (!e->from) {
         e->from = rfc822_new_address ();
-        e->from->personal = str_dup (line + 6);
+        e->from->personal = str_dup (p);
       }
       matched = 1;
     }
@@ -1080,7 +1084,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);
+            mem_free (&e->list_post);
             e->list_post = str_substrdup (beg, end);
             break;
           }
@@ -1098,7 +1102,7 @@ int mutt_parse_rfc822_line (ENVELOPE * e, HEADER * hdr, char *line, char *p,
     }
     else if (!ascii_strcasecmp (line + 1, "essage-id")) {
       /* We add a new "Message-Id:" when building a message */
-      FREE (&e->message_id);
+      mem_free (&e->message_id);
       e->message_id = extract_message_id (p);
       matched = 1;
     }
@@ -1119,7 +1123,7 @@ int mutt_parse_rfc822_line (ENVELOPE * e, HEADER * hdr, char *line, char *p,
 #ifdef USE_NNTP
   case 'n':
     if (!str_casecmp (line + 1, "ewsgroups")) {
-      FREE (&e->newsgroups);
+      mem_free (&e->newsgroups);
       str_skip_trailws (p);
       e->newsgroups = str_dup (str_skip_initws (p));
       matched = 1;
@@ -1293,7 +1297,7 @@ ENVELOPE *mutt_read_rfc822_header (FILE * f, HEADER * hdr, short user_hdrs,
 {
   ENVELOPE *e = mutt_new_envelope ();
   LIST *last = NULL;
-  char *line = safe_malloc (LONG_STRING);
+  char *line = mem_malloc (LONG_STRING);
   char *p;
   long loc;
   int matched;
@@ -1316,7 +1320,7 @@ ENVELOPE *mutt_read_rfc822_header (FILE * f, HEADER * hdr, short user_hdrs,
   }
 
   while ((loc = ftell (f)),
-         *(line = read_rfc822_line (f, line, &linelen)) != 0) {
+         *(line = mutt_read_rfc822_line (f, line, &linelen)) != 0) {
     matched = 0;
 
     if ((p = strpbrk (line, ": \t")) == NULL || *p != ':') {
@@ -1384,36 +1388,16 @@ ENVELOPE *mutt_read_rfc822_header (FILE * f, HEADER * hdr, short user_hdrs,
 
   }
 
-  FREE (&line);
+  mem_free (&line);
 
   if (hdr) {
     hdr->content->hdr_offset = hdr->offset;
     hdr->content->offset = ftell (f);
-
-    /* do RFC2047 decoding */
-    rfc2047_decode_adrlist (e->from);
-    rfc2047_decode_adrlist (e->to);
-    rfc2047_decode_adrlist (e->cc);
-    rfc2047_decode_adrlist (e->bcc);
-    rfc2047_decode_adrlist (e->reply_to);
-    rfc2047_decode_adrlist (e->mail_followup_to);
-    rfc2047_decode_adrlist (e->return_path);
-    rfc2047_decode_adrlist (e->sender);
-
-    if (e->subject) {
-      regmatch_t pmatch[1];
-
-      rfc2047_decode (&e->subject);
-
-      if (regexec (ReplyRegexp.rx, e->subject, 1, pmatch, 0) == 0)
-        e->real_subj = e->subject + pmatch[0].rm_eo;
-      else
-        e->real_subj = e->subject;
-    }
-
+    rfc2047_decode_envelope (e);
     /* check for missing or invalid date */
     if (hdr->date_sent <= 0) {
-      debug_print (1, ("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;
     }
   }