wibble.
[apps/madmutt.git] / sendlib.c
index e5bb57f..ae595c3 100644 (file)
--- a/sendlib.c
+++ b/sendlib.c
@@ -9,32 +9,14 @@
 
 #define _SENDLIB_C 1
 
-#if HAVE_CONFIG_H
-# include "config.h"
-#endif
+#include <lib-lib/lib-lib.h>
 
-#include <string.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <errno.h>
-#include <ctype.h>
-#include <sys/stat.h>
 #include <signal.h>
-#include <sys/wait.h>
-#include <fcntl.h>
 #include <sys/utsname.h>
 
-#include <lib-lib/mem.h>
-#include <lib-lib/ascii.h>
-#include <lib-lib/str.h>
-#include <lib-lib/macros.h>
-#include <lib-lib/file.h>
-
 #include <lib-sys/exit.h>
 #include <lib-sys/mutt_signal.h>
-
 #include <lib-mime/mime.h>
-
 #include <lib-ui/curses.h>
 
 #include "mutt.h"
@@ -364,8 +346,6 @@ int mutt_write_mime_header (BODY * a, FILE * f)
   return (ferror (f) ? -1 : 0);
 }
 
-# define write_as_text_part(a)  (mutt_is_text_part(a) || mutt_is_application_pgp(a))
-
 int mutt_write_mime_body (BODY * a, FILE * f)
 {
   const char *p;
@@ -414,6 +394,7 @@ int mutt_write_mime_body (BODY * a, FILE * f)
   else
     fc = fgetconv_open (fpin, 0, 0, 0);
 
+#define write_as_text_part(a)  (mutt_is_text_part(a) || mutt_is_application_pgp(a))
   if (a->encoding == ENCQUOTEDPRINTABLE)
     encode_quoted (fc, f, write_as_text_part (a));
   else if (a->encoding == ENCBASE64)
@@ -422,6 +403,7 @@ int mutt_write_mime_body (BODY * a, FILE * f)
     encode_8bit (fc, f, write_as_text_part (a));
   else
     mutt_copy_stream (fpin, f);
+#undef write_as_text_part
 
   fgetconv_close (&fc);
   fclose (fpin);
@@ -429,8 +411,6 @@ int mutt_write_mime_body (BODY * a, FILE * f)
   return (ferror (f) ? -1 : 0);
 }
 
-#undef write_as_text_part
-
 typedef struct {
   int from;
   int whitespace;
@@ -1095,22 +1075,16 @@ void mutt_stamp_attachment (BODY * a)
 
 /* Get a body's character set */
 
-char *mutt_get_body_charset (char *d, ssize_t dlen, BODY * b)
+char *mutt_get_body_charset(char *d, ssize_t dlen, BODY * b)
 {
-  const char *p = NULL;
-
-  if (b && b->type != TYPETEXT)
-    return NULL;
-
-  if (b)
-    p = parameter_getval(b->parameter, "charset");
+    const char *p;
 
-  if (p)
-    charset_canonicalize (d, dlen, p);
-  else
-    m_strcpy(d, dlen, "us-ascii");
+    if (b && b->type != TYPETEXT)
+        return NULL;
 
-  return d;
+    p = b ? parameter_getval(b->parameter, "charset") : NULL;
+    charset_canonicalize(d, dlen, p);
+    return d;
 }
 
 
@@ -1223,23 +1197,8 @@ BODY *mutt_make_file_attach (const char *path)
   /* Attempt to determine the appropriate content-type based on the filename
    * suffix.
    */
-
-#if 0
-
-  if ((n =
-       mutt_lookup_mime_type (buf, sizeof (buf), xbuf, sizeof (xbuf),
-                              path)) != TYPEOTHER || *xbuf != '\0') {
-    att->type = n;
-    att->subtype = m_strdup(buf);
-    att->xtype = m_strdup(xbuf);
-  }
-
-#else
-
   mutt_lookup_mime_type (att, path);
 
-#endif
-
   if ((info = mutt_get_content_info (path, att)) == NULL) {
     body_list_wipe(&att);
     return NULL;
@@ -1254,15 +1213,14 @@ BODY *mutt_make_file_attach (const char *path)
        */
       att->type = TYPETEXT;
       att->subtype = m_strdup("plain");
-    }
-    else {
+    } else {
       att->type = TYPEAPPLICATION;
       att->subtype = m_strdup("octet-stream");
     }
   }
 
   mutt_update_encoding (att);
-  return (att);
+  return att;
 }
 
 static int get_toplevel_encoding (BODY * a)
@@ -1774,17 +1732,8 @@ send_msg(const char *path, const char **args, const char *msg, char **tempfile)
     setsid ();
 
     /* next we close all open files */
-#if defined(OPEN_MAX)
-    for (fd = 0; fd < OPEN_MAX; fd++)
-      close (fd);
-#elif defined(_POSIX_OPEN_MAX)
-    for (fd = 0; fd < _POSIX_OPEN_MAX; fd++)
+    for (fd = 0; fd < getdtablesize(); fd++)
       close (fd);
-#else
-    close (0);
-    close (1);
-    close (2);
-#endif
 
     /* now the second fork() */
     if ((pid = fork ()) == 0) {
@@ -2187,41 +2136,6 @@ int mutt_bounce_message (FILE * fp, HEADER * h, address_t * to)
   return ret;
 }
 
-
-/* given a list of addresses, return a list of unique addresses */
-address_t *mutt_remove_duplicates (address_t * addr)
-{
-  address_t *top = addr;
-  address_t **last = &top;
-  address_t *tmp;
-  int dodup = 0;
-
-  while (addr) {
-    for (tmp = top; tmp && tmp != addr; tmp = tmp->next) {
-      if (tmp->mailbox && addr->mailbox &&
-          !ascii_strcasecmp (addr->mailbox, tmp->mailbox)) {
-        dodup = 1;
-        break;
-      }
-    }
-
-    if (dodup) {
-      *last = addr->next;
-
-      addr->next = NULL;
-      address_list_wipe(&addr);
-
-      addr = *last;
-    }
-    else {
-      last = &addr->next;
-      addr = addr->next;
-    }
-  }
-
-  return (top);
-}
-
 static void set_noconv_flags (BODY * b, short flag)
 {
   for (; b; b = b->next) {