more and more cleansing
[apps/madmutt.git] / muttlib.c
index bc659a7..931c98b 100644 (file)
--- a/muttlib.c
+++ b/muttlib.c
@@ -13,6 +13,9 @@
 #endif
 
 #include "mutt.h"
+#include "ascii.h"
+#include "buffer.h"
+#include "enter.h"
 #include "mutt_curses.h"
 #include "mime.h"
 #include "mx.h"
@@ -20,6 +23,7 @@
 #include "attach.h"
 
 #include "reldate.h"
+#include "version.h"
 
 #ifdef USE_IMAP
 #include "imap.h"
@@ -45,6 +49,8 @@
 #include <sys/types.h>
 #include <utime.h>
 
+#define SW              (option(OPTMBOXPANE)?SidebarWidth:0)
+
 BODY *mutt_new_body (void)
 {
   BODY *p = (BODY *) mem_calloc (1, sizeof (BODY));
@@ -61,7 +67,7 @@ BODY *mutt_new_body (void)
  * Renamed to mutt_adv_mktemp so I only have to change where it's
  * called, and not all possible cases.
  */
-void mutt_adv_mktemp (char *s, size_t l)
+void mutt_adv_mktemp (const char* dir, char *s, size_t l)
 {
   char buf[_POSIX_PATH_MAX];
   char tmp[_POSIX_PATH_MAX];
@@ -69,7 +75,7 @@ void mutt_adv_mktemp (char *s, size_t l)
   size_t sl;
   struct stat sb;
 
-  strfcpy (buf, NONULL (Tempdir), sizeof (buf));
+  strfcpy (buf, dir && *dir ? dir : NONULL (Tempdir), sizeof (buf));
   mutt_expand_path (buf, sizeof (buf));
   if (s[0] == '\0') {
     snprintf (s, l, "%s/muttXXXXXX", buf);
@@ -113,7 +119,7 @@ int mutt_copy_body (FILE * fp, BODY ** tgt, BODY * src)
     tmp[0] = '\0';
   }
 
-  mutt_adv_mktemp (tmp, sizeof (tmp));
+  mutt_adv_mktemp (NULL, tmp, sizeof (tmp));
   if (mutt_save_attachment (fp, src, tmp, 0, NULL) == -1)
     return -1;
 
@@ -215,43 +221,6 @@ void mutt_free_parameter (PARAMETER ** p)
   *p = 0;
 }
 
-LIST *mutt_add_list (LIST * head, const char *data) {
-  size_t len = str_len (data);
-  return (mutt_add_list_n (head, data, len ? len + 1 : 0));
-}
-
-LIST *mutt_add_list_n (LIST *head, const void *data, size_t len) {
-  LIST *tmp;
-
-  for (tmp = head; tmp && tmp->next; tmp = tmp->next);
-
-  if (tmp) {
-    tmp->next = mem_malloc (sizeof (LIST));
-    tmp = tmp->next;
-  } else
-    head = tmp = mem_malloc (sizeof (LIST));
-
-  tmp->data = mem_malloc (len);
-  if (len)
-    memcpy (tmp->data, data, len);
-  tmp->next = NULL;
-  return head;
-}
-
-void mutt_free_list (LIST ** list)
-{
-  LIST *p;
-
-  if (!list)
-    return;
-  while (*list) {
-    p = *list;
-    *list = (*list)->next;
-    mem_free (&p->data);
-    mem_free (&p);
-  }
-}
-
 HEADER *mutt_dup_header (HEADER * h)
 {
   HEADER *hnew;
@@ -1046,9 +1015,7 @@ void mutt_FormatString (char *dest,     /* output buffer */
         if (DrawFullLine || option (OPTSTATUSONTOP))
           count = (COLS < destlen ? COLS : destlen);
         else
-          count =
-            ((COLS - SidebarWidth) <
-             destlen ? (COLS - SidebarWidth) : destlen);
+          count = ((COLS - SW) < destlen ? (COLS - SW) : destlen);
         if (count > col) {
           count -= col;         /* how many columns left on this line */
           mutt_FormatString (buf, sizeof (buf), src, callback, data, flags);
@@ -1295,7 +1262,6 @@ void mutt_sleep (short s)
 }
 
 /* Decrease a file's modification time by 1 second */
-
 time_t mutt_decrease_mtime (const char *f, struct stat *st)
 {
   struct utimbuf utim;
@@ -1318,12 +1284,29 @@ time_t mutt_decrease_mtime (const char *f, struct stat *st)
   return mtime;
 }
 
-const char *mutt_make_version (void)
+/* sets mtime of 'to' to mtime of 'from' */
+void mutt_set_mtime (const char* from, const char* to) {
+  struct utimbuf utim;
+  struct stat st;
+
+  if (stat (from, &st) != -1) {
+    utim.actime = st.st_mtime;
+    utim.modtime = st.st_mtime;
+    utime (to, &utim);
+  }
+}
+
+const char *mutt_make_version (int full)
 {
   static char vstring[STRING];
 
-  snprintf (vstring, sizeof (vstring), "Mutt-ng %s (%s) based on Mutt 1.5.9",
-            MUTT_VERSION, ReleaseDate);
+  if (full)
+    snprintf (vstring, sizeof (vstring), "Mutt-ng %s-r%s (based "
+              "on Mutt 1.5.11/%s)", MUTT_VERSION, MUTT_REVISION,
+              ReleaseDate);
+  else
+    snprintf (vstring, sizeof (vstring), "mutt-ng/%s-r%s",
+              MUTT_VERSION, MUTT_REVISION);
   return vstring;
 }
 
@@ -1371,7 +1354,7 @@ int mutt_match_spam_list (const char *s, SPAM_LIST * l, char *text, int x)
       for (p = l->template; *p;) {
         if (*p == '%') {
           n = atoi (++p);       /* find pmatch index */
-          while (isdigit (*p))
+          while (isdigit ((unsigned char) *p))
             ++p;                /* skip subst token */
           for (i = pmatch[n].rm_so; (i < pmatch[n].rm_eo) && (tlen < x); i++)
             text[tlen++] = s[i];