reorganize code a lot: create a lib-crypt with everything smime or gpg
[apps/madmutt.git] / muttlib.c
index 04c0b3a..e3a7cad 100644 (file)
--- a/muttlib.c
+++ b/muttlib.c
 #include <lib-lib/buffer.h>
 #include <lib-lib/file.h>
 
+#include <lib-mime/mime.h>
+
 #include "mutt.h"
 #include "enter.h"
 #include "mutt_curses.h"
-#include "mime.h"
 #include "mx.h"
 #include "url.h"
 #include "attach.h"
 
 #include "version.h"
 
-#ifdef USE_IMAP
-#include "imap.h"
-#include "imap/mx_imap.h"
-#endif
+#include <imap/imap.h>
+#include <imap/mx_imap.h>
 
-#include "mutt_crypt.h"
+#include <lib-crypt/crypt.h>
 
 #include "lib/debug.h"
 
@@ -243,9 +242,7 @@ void mutt_free_header (HEADER ** h)
 #ifdef MIXMASTER
   mutt_free_list (&(*h)->chain);
 #endif
-#if defined USE_POP || defined USE_IMAP || defined USE_NNTP
   p_delete(&(*h)->data);
-#endif
   p_delete(h);
 }
 
@@ -338,13 +335,11 @@ char *_mutt_expand_path (char *s, size_t slen, int rx)
     case '=':
     case '+':
       {
-#ifdef USE_IMAP
         /* if folder = imap[s]://host/: don't append slash */
         if (imap_is_magic (NONULL (Maildir), NULL) == M_IMAP && 
             Maildir[m_strlen(Maildir) - 1] == '/')
           m_strcpy(p, sizeof(p), NONULL(Maildir));
         else
-#endif
           snprintf (p, sizeof (p), "%s/", NONULL (Maildir));
 
         tail = s + 1;
@@ -356,7 +351,7 @@ char *_mutt_expand_path (char *s, size_t slen, int rx)
     case '@':
       {
         HEADER *h;
-        ADDRESS *alias;
+        address_t *alias;
 
         if ((alias = mutt_lookup_alias (s + 1))) {
           h = mutt_new_header ();
@@ -502,7 +497,7 @@ void mutt_set_parameter (const char *attribute, const char *value,
 
   for (q = *p; q; q = q->next) {
     if (ascii_strcasecmp (attribute, q->attribute) == 0) {
-      str_replace (&q->value, value);
+      m_strreplace(&q->value, value);
       return;
     }
   }
@@ -541,9 +536,9 @@ int mutt_needs_mailcap (BODY * m)
     break;
 
   case TYPEAPPLICATION:
-    if ((WithCrypto & APPLICATION_PGP) && mutt_is_application_pgp (m))
+    if (mutt_is_application_pgp (m))
       return 0;
-    if ((WithCrypto & APPLICATION_SMIME) && mutt_is_application_smime (m))
+    if (mutt_is_application_smime (m))
       return 0;
     break;
 
@@ -560,7 +555,7 @@ int mutt_is_text_part (BODY * b)
   int t = b->type;
   char *s = b->subtype;
 
-  if ((WithCrypto & APPLICATION_PGP) && mutt_is_application_pgp (b))
+  if (mutt_is_application_pgp (b))
     return 0;
 
   if (t == TYPETEXT)
@@ -571,7 +566,7 @@ int mutt_is_text_part (BODY * b)
       return 1;
   }
 
-  if ((WithCrypto & APPLICATION_PGP) && t == TYPEAPPLICATION) {
+  if (t == TYPEAPPLICATION) {
     if (!ascii_strcasecmp ("pgp-keys", s))
       return 1;
   }
@@ -583,14 +578,14 @@ void mutt_free_envelope (ENVELOPE ** p)
 {
   if (!*p)
     return;
-  rfc822_free_address (&(*p)->return_path);
-  rfc822_free_address (&(*p)->from);
-  rfc822_free_address (&(*p)->to);
-  rfc822_free_address (&(*p)->cc);
-  rfc822_free_address (&(*p)->bcc);
-  rfc822_free_address (&(*p)->sender);
-  rfc822_free_address (&(*p)->reply_to);
-  rfc822_free_address (&(*p)->mail_followup_to);
+  address_delete (&(*p)->return_path);
+  address_delete (&(*p)->from);
+  address_delete (&(*p)->to);
+  address_delete (&(*p)->cc);
+  address_delete (&(*p)->bcc);
+  address_delete (&(*p)->sender);
+  address_delete (&(*p)->reply_to);
+  address_delete (&(*p)->mail_followup_to);
 
   p_delete(&(*p)->list_post);
   p_delete(&(*p)->subject);
@@ -676,7 +671,7 @@ void mutt_free_alias (ALIAS ** p)
     t = *p;
     *p = (*p)->next;
     p_delete(&t->name);
-    rfc822_free_address (&t->addr);
+    address_delete (&t->addr);
     p_delete(&t);
   }
 }
@@ -690,12 +685,10 @@ void mutt_pretty_mailbox (char *s)
 
   scheme = url_check_scheme (s);
 
-#ifdef USE_IMAP
   if (scheme == U_IMAP || scheme == U_IMAPS) {
     imap_pretty_mailbox (s);
     return;
   }
-#endif
 
   /* if s is an url, only collapse path component */
   if (scheme != U_UNKNOWN) {
@@ -828,7 +821,7 @@ int mutt_check_overwrite (const char *attname, const char *path,
               (_("File is a directory, save under it? [(y)es, (n)o, (a)ll]"),
                _("yna"))) {
       case 3:                  /* all */
-        str_replace (directory, fname);
+        m_strreplace(directory, fname);
         break;
       case 1:                  /* yes */
         p_delete(directory);
@@ -878,7 +871,7 @@ int mutt_check_overwrite (const char *attname, const char *path,
   return 0;
 }
 
-void mutt_save_path (char *d, size_t dsize, ADDRESS * a)
+void mutt_save_path (char *d, size_t dsize, address_t * a)
 {
   if (a && a->mailbox) {
     m_strcpy(d, dsize, a->mailbox);
@@ -888,13 +881,13 @@ void mutt_save_path (char *d, size_t dsize, ADDRESS * a)
       if ((p = strpbrk (d, "%@")))
         *p = 0;
     }
-    str_tolower (d);
+    m_strtolower(d);
   }
   else
     *d = 0;
 }
 
-void mutt_safe_path (char *s, size_t l, ADDRESS * a)
+void mutt_safe_path (char *s, size_t l, address_t * a)
 {
   char *p;
 
@@ -1069,7 +1062,7 @@ void mutt_FormatString (char *dest,     /* output buffer */
                     data, flags);
 
         if (lower)
-          str_tolower (buf);
+          m_strtolower(buf);
         if (nodots) {
           char *p = buf;
 
@@ -1177,13 +1170,11 @@ int mutt_save_confirm (const char *s, struct stat *st)
 
   magic = mx_get_magic (s);
 
-#ifdef USE_POP
   if (magic == M_POP) {
     mutt_error _("Can't save message to POP mailbox.");
 
     return 1;
   }
-#endif
 
 #ifdef USE_NNTP
   if (magic == M_NNTP) {
@@ -1212,9 +1203,7 @@ int mutt_save_confirm (const char *s, struct stat *st)
     }
   }
   else {
-#ifdef USE_IMAP
     if (magic != M_IMAP)
-#endif /* execute the block unconditionally if we don't use imap */
     {
       st->st_mtime = 0;
       st->st_atime = 0;
@@ -1391,7 +1380,7 @@ int mutt_cmp_header (const HEADER * h1, const HEADER * h2) {
 }
 
 /* return 1 if address lists are strictly identical */
-int mutt_cmp_addr (const ADDRESS * a, const ADDRESS * b)
+int mutt_cmp_addr (const address_t * a, const address_t * b)
 {
   while (a && b) {
     if (m_strcmp(a->mailbox, b->mailbox) ||