move mutt_get_parameter -> parameter_getval into mime.c
[apps/madmutt.git] / muttlib.c
index 2938066..5ad138c 100644 (file)
--- a/muttlib.c
+++ b/muttlib.c
 # include "config.h"
 #endif
 
-#include <string.h>
 #include <ctype.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <sys/wait.h>
 #include <errno.h>
-#include <sys/stat.h>
 #include <fcntl.h>
-#include <time.h>
+#include <grp.h>
+#include <pwd.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/stat.h>
 #include <sys/types.h>
+#include <sys/wait.h>
+#include <time.h>
+#include <unistd.h>
 #include <utime.h>
 
 #include <lib-lib/mem.h>
@@ -30,7 +32,6 @@
 #include <lib-lib/macros.h>
 #include <lib-lib/buffer.h>
 #include <lib-lib/file.h>
-#include <lib-lib/debug.h>
 #include <lib-lib/url.h>
 
 #include <lib-mime/mime.h>
@@ -38,6 +39,7 @@
 #include <lib-ui/curses.h>
 #include <lib-ui/enter.h>
 
+#include "alias.h"
 #include "mutt.h"
 #include "mx.h"
 #include "attach.h"
@@ -166,23 +168,14 @@ int mutt_copy_body (FILE * fp, BODY ** tgt, BODY * src)
 }
 
 
-
-void mutt_free_body (BODY ** p)
+static void body_wipe(BODY *b)
 {
-  BODY *a = *p, *b;
-
-  while (a) {
-    b = a;
-    a = a->next;
-
     if (b->parameter)
-      parameter_list_wipe(&b->parameter);
+        parameter_list_wipe(&b->parameter);
+
     if (b->unlink && b->filename) {
-      debug_print (1, ("unlinking %s.\n", b->filename));
-      unlink (b->filename);
+        unlink (b->filename);
     }
-    else if (b->filename)
-      debug_print (1, ("not unlinking %s.\n", b->filename));
 
     p_delete(&b->filename);
     p_delete(&b->content);
@@ -192,18 +185,25 @@ void mutt_free_body (BODY ** p)
     p_delete(&b->form_name);
 
     if (b->hdr) {
-      /* Don't free twice (b->hdr->content = b->parts) */
-      b->hdr->content = NULL;
-      header_delete(&b->hdr);
+        /* Don't free twice (b->hdr->content = b->parts) */
+        b->hdr->content = NULL;
+        header_delete(&b->hdr);
     }
 
     if (b->parts)
-      mutt_free_body (&b->parts);
+        mutt_free_body(&b->parts);
+}
 
-    p_delete(&b);
-  }
+DO_DELETE(BODY, body);
+
+void mutt_free_body(BODY **p)
+{
+    while (*p) {
+        BODY *b = *p;
+        *p = b->next;
 
-  *p = 0;
+        body_delete(&b);
+    }
 }
 
 HEADER *mutt_dup_header (HEADER * h)
@@ -401,51 +401,40 @@ char *_mutt_expand_path (char *s, ssize_t slen, int rx)
   return (s);
 }
 
-char *mutt_get_parameter (const char *s, PARAMETER * p)
-{
-  for (; p; p = p->next)
-    if (ascii_strcasecmp (s, p->attribute) == 0)
-      return (p->value);
-
-  return NULL;
-}
-
 void mutt_set_parameter (const char *attribute, const char *value,
                          PARAMETER ** p)
 {
-  PARAMETER *q;
+    PARAMETER *q;
 
-  if (!value) {
-    mutt_delete_parameter (attribute, p);
-    return;
-  }
+    if (!value) {
+        mutt_delete_parameter (attribute, p);
+        return;
+    }
 
-  for (q = *p; q; q = q->next) {
-    if (ascii_strcasecmp (attribute, q->attribute) == 0) {
-      m_strreplace(&q->value, value);
-      return;
+    for (q = *p; q; q = q->next) {
+        if (ascii_strcasecmp (attribute, q->attribute) == 0) {
+            m_strreplace(&q->value, value);
+            return;
+        }
     }
-  }
 
-  q = parameter_new();
-  q->attribute = m_strdup(attribute);
-  q->value = m_strdup(value);
-  q->next = *p;
-  *p = q;
+    q = parameter_new();
+    q->attribute = m_strdup(attribute);
+    q->value = m_strdup(value);
+    parameter_list_push(p, q);
 }
 
 void mutt_delete_parameter (const char *attribute, PARAMETER ** p)
 {
-  PARAMETER *q;
+    while (*p) {
+        if (!ascii_strcasecmp(attribute, (*p)->attribute)) {
+            PARAMETER *q = parameter_list_pop(p);
+            parameter_delete(&q);
+            return;
+        }
 
-  for (q = *p; q; p = &q->next, q = q->next) {
-    if (ascii_strcasecmp (attribute, q->attribute) == 0) {
-      *p = q->next;
-      q->next = NULL;
-      parameter_list_wipe(&q);
-      return;
+        p = &(*p)->next;
     }
-  }
 }
 
 /* returns 1 if Mutt can't display this type of data, 0 otherwise */
@@ -549,7 +538,6 @@ void _mutt_mktemp (char *s, const char *src, int line)
   snprintf (s, _POSIX_PATH_MAX, "%s/madmutt-%s-%d-%d-%d-%x%x", NONULL (Tempdir),
             NONULL (Hostname), (int) getuid (), (int) getpid (), Counter++, 
             (unsigned int) rand(), (unsigned int) rand());
-  debug_print (1, ("%s:%d: mutt_mktemp returns \"%s\".\n", src, line, s));
   unlink (s);
 }
 
@@ -1207,8 +1195,6 @@ int mutt_match_spam_list (const char *s, SPAM_LIST * l, char *text, int x)
     /* Does this pattern match? */
     if (regexec(l->rx->rx, s, l->nmatch, (regmatch_t *)pmatch, (int) 0) == 0)
     {
-      debug_print (5, ("%s matches %s\n%d subst", s, l->rx->pattern, l->rx->rx->re_nsub));
-
       /* Copy template into text, with substitutions. */
       for (p = l->template; *p;) {
         if (*p == '%') {
@@ -1223,7 +1209,6 @@ int mutt_match_spam_list (const char *s, SPAM_LIST * l, char *text, int x)
         }
       }
       text[tlen] = '\0';
-      debug_print (5, ("\"%s\"\n", text));
       return 1;
     }
   }