Rocco Rutte:
[apps/madmutt.git] / rfc822.c
index cc13a67..d3b5d56 100644 (file)
--- a/rfc822.c
+++ b/rfc822.c
@@ -1,19 +1,10 @@
 /*
+ * Copyright notice from original mutt:
  * Copyright (C) 1996-2000 Michael R. Elkins <me@mutt.org>
- * 
- *     This program is free software; you can redistribute it and/or modify
- *     it under the terms of the GNU General Public License as published by
- *     the Free Software Foundation; either version 2 of the License, or
- *     (at your option) any later version.
- * 
- *     This program is distributed in the hope that it will be useful,
- *     but WITHOUT ANY WARRANTY; without even the implied warranty of
- *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *     GNU General Public License for more details.
- * 
- *     You should have received a copy of the GNU General Public License
- *     along with this program; if not, write to the Free Software
- *     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
+ *
+ * This file is part of mutt-ng, see http://www.muttng.org/.
+ * It's licensed under the GNU General Public License,
+ * please see the file GPL in the top level source directory.
  */
 
 #if HAVE_CONFIG_H
 #include <ctype.h>
 #include <stdlib.h>
 
-#ifndef TESTING
 #include "mutt.h"
-#else
-#define safe_strdup strdup
-#define safe_malloc malloc
-#define SKIPWS(x) while(isspace(*x))x++
-#define FREE(x) safe_free(x)
-#define ISSPACE isspace
-#define strfcpy(a,b,c) {if (c) {strncpy(a,b,c);a[c-1]=0;}}
-#define STRING 128
-#include "rfc822.h"
-#endif
-
 #include "mutt_idna.h"
 
+#include "lib/mem.h"
+#include "lib/intl.h"
+#include "lib/str.h"
+
 #define terminate_string(a, b, c) do { if ((b) < (c)) a[(b)] = 0; else \
        a[(c)] = 0; } while (0)
 
@@ -347,7 +330,7 @@ ADDRESS *rfc822_parse_adrlist (ADDRESS * top, const char *s)
 
 #ifdef EXACT_ADDRESS
       if (last && !last->val)
-        last->val = mutt_substrdup (begin, s);
+        last->val = str_substrdup (begin, s);
 #endif
       commentlen = 0;
       phraselen = 0;
@@ -379,7 +362,7 @@ ADDRESS *rfc822_parse_adrlist (ADDRESS * top, const char *s)
       last = cur;
 
 #ifdef EXACT_ADDRESS
-      last->val = mutt_substrdup (begin, s);
+      last->val = str_substrdup (begin, s);
 #endif
 
       phraselen = 0;
@@ -400,7 +383,7 @@ ADDRESS *rfc822_parse_adrlist (ADDRESS * top, const char *s)
       }
 #ifdef EXACT_ADDRESS
       if (last && !last->val)
-        last->val = mutt_substrdup (begin, s);
+        last->val = str_substrdup (begin, s);
 #endif
 
       /* add group terminator */
@@ -470,7 +453,7 @@ ADDRESS *rfc822_parse_adrlist (ADDRESS * top, const char *s)
   }
 #ifdef EXACT_ADDRESS
   if (last)
-    last->val = mutt_substrdup (begin, s);
+    last->val = str_substrdup (begin, s);
 #endif
 
   return top;
@@ -482,7 +465,7 @@ void rfc822_qualify (ADDRESS * addr, const char *host)
 
   for (; addr; addr = addr->next)
     if (!addr->group && addr->mailbox && strchr (addr->mailbox, '@') == NULL) {
-      p = safe_malloc (mutt_strlen (addr->mailbox) + mutt_strlen (host) + 2);
+      p = safe_malloc (safe_strlen (addr->mailbox) + safe_strlen (host) + 2);
       sprintf (p, "%s@%s", addr->mailbox, host);        /* __SPRINTF_CHECKED__ */
       FREE (&addr->mailbox);
       addr->mailbox = p;
@@ -530,7 +513,10 @@ void rfc822_write_address_single (char *buf, size_t buflen, ADDRESS * addr,
     if (!buflen)
       goto done;
     strfcpy (pbuf, addr->val, buflen);
-    len = mutt_strlen (pbuf);
+    len = safe_strlen (pbuf);
+    /* dirty fix to un-break EXACT_ADDRESS */
+    if (pbuf[len-1] == '\n')
+      pbuf[--len] = '\0';
     pbuf += len;
     buflen -= len;
     if (addr->group) {
@@ -571,7 +557,7 @@ void rfc822_write_address_single (char *buf, size_t buflen, ADDRESS * addr,
       if (!buflen)
         goto done;
       strfcpy (pbuf, addr->personal, buflen);
-      len = mutt_strlen (pbuf);
+      len = safe_strlen (pbuf);
       pbuf += len;
       buflen -= len;
     }
@@ -594,11 +580,11 @@ void rfc822_write_address_single (char *buf, size_t buflen, ADDRESS * addr,
       goto done;
     if (ascii_strcmp (addr->mailbox, "@") && !display) {
       strfcpy (pbuf, addr->mailbox, buflen);
-      len = mutt_strlen (pbuf);
+      len = safe_strlen (pbuf);
     }
     else if (ascii_strcmp (addr->mailbox, "@") && display) {
       strfcpy (pbuf, mutt_addr_for_display (addr), buflen);
-      len = mutt_strlen (pbuf);
+      len = safe_strlen (pbuf);
     }
     else {
       *pbuf = '\0';
@@ -642,7 +628,7 @@ void rfc822_write_address (char *buf, size_t buflen, ADDRESS * addr,
                            int display)
 {
   char *pbuf = buf;
-  size_t len = mutt_strlen (buf);
+  size_t len = safe_strlen (buf);
 
   buflen--;                     /* save room for the terminal nul */
 
@@ -669,7 +655,7 @@ void rfc822_write_address (char *buf, size_t buflen, ADDRESS * addr,
 
     /* this should be safe since we always have at least 1 char passed into
        the above call, which means `pbuf' should always be nul terminated */
-    len = mutt_strlen (pbuf);
+    len = safe_strlen (pbuf);
     pbuf += len;
     buflen -= len;
 
@@ -737,31 +723,3 @@ ADDRESS *rfc822_append (ADDRESS ** a, ADDRESS * b)
     tmp = tmp->next;
   return tmp;
 }
-
-#ifdef TESTING
-int safe_free (void **p)
-{
-  free (*p);                    /* __MEM_CHECKED__ */
-  *p = 0;
-}
-
-int main (int argc, char **argv)
-{
-  ADDRESS *list;
-  char buf[256];
-
-# if 0
-  char *str =
-    "michael, Michael Elkins <me@mutt.org>, testing a really complex address: this example <@contains.a.source.route,@with.multiple.hosts:address@example.com>;, lothar@of.the.hillpeople (lothar)";
-# else
-  char *str = "a b c ";
-# endif
-
-  list = rfc822_parse_adrlist (NULL, str);
-  buf[0] = 0;
-  rfc822_write_address (buf, sizeof (buf), list);
-  rfc822_free_address (&list);
-  puts (buf);
-  exit (0);
-}
-#endif