aboutsummaryrefslogtreecommitdiffstats
path: root/camel/camel-internet-address.c
diff options
context:
space:
mode:
authorNot Zed <NotZed@Ximian.com>2001-02-13 08:30:45 +0800
committerMichael Zucci <zucchi@src.gnome.org>2001-02-13 08:30:45 +0800
commit7fc592861825abf6bf91a324d636ef433f8100b8 (patch)
tree993cdda1899cdf2a8939a0436ad69e48fcd08d06 /camel/camel-internet-address.c
parentf856d19202dc273ecbae3b9116d2d23fe4915d28 (diff)
downloadgsoc2013-evolution-7fc592861825abf6bf91a324d636ef433f8100b8.tar
gsoc2013-evolution-7fc592861825abf6bf91a324d636ef433f8100b8.tar.gz
gsoc2013-evolution-7fc592861825abf6bf91a324d636ef433f8100b8.tar.bz2
gsoc2013-evolution-7fc592861825abf6bf91a324d636ef433f8100b8.tar.lz
gsoc2013-evolution-7fc592861825abf6bf91a324d636ef433f8100b8.tar.xz
gsoc2013-evolution-7fc592861825abf6bf91a324d636ef433f8100b8.tar.zst
gsoc2013-evolution-7fc592861825abf6bf91a324d636ef433f8100b8.zip
Add address headers to list that we dont fold when writing. The are
2001-02-12 Not Zed <NotZed@Ximian.com> * camel-mime-part.c (init_header_name_table): Add address headers to list that we dont fold when writing. The are properly formatted as we build them. (write_to_stream): DOH, lookup the header name in the formatted hash table, not the value, that would never have worked. * camel-internet-address.c (camel_internet_address_encode_address): Changed to take a parameter saying how much we've printed so far. We now fold the header as we format it. We dont fold addresses, even if they are too long, we simply put them on another line by themselves: this should make the result more parsable by mailers that can't handle split up addresses (which are legal). (internet_encode): Fix for changes to above. svn path=/trunk/; revision=8198
Diffstat (limited to 'camel/camel-internet-address.c')
-rw-r--r--camel/camel-internet-address.c56
1 files changed, 50 insertions, 6 deletions
diff --git a/camel/camel-internet-address.c b/camel/camel-internet-address.c
index 94ce51261a..e97e9029eb 100644
--- a/camel/camel-internet-address.c
+++ b/camel/camel-internet-address.c
@@ -22,6 +22,7 @@
#include "camel-internet-address.h"
#include <stdio.h>
+#include <string.h>
#define d(x)
@@ -116,7 +117,8 @@ internet_encode (CamelAddress *a)
int i;
GString *out;
char *ret;
-
+ int len = 6; /* "From: ", assume longer of the address headers */
+
if (a->addresses->len == 0)
return NULL;
@@ -129,7 +131,7 @@ internet_encode (CamelAddress *a)
if (i != 0)
g_string_append(out, ", ");
- enc = camel_internet_address_encode_address(addr->name, addr->address);
+ enc = camel_internet_address_encode_address(&len, addr->name, addr->address);
g_string_sprintfa(out, "%s", enc);
g_free(enc);
}
@@ -398,27 +400,69 @@ camel_internet_address_find_address(CamelInternetAddress *a, const char *address
/**
* camel_internet_address_encode_address:
+ * @len: The encoded length so far, of this line
* @name:
* @addr:
*
- * Encode a single address ready for internet usage.
+ * Encode a single address ready for internet usage. Header folding
+ * as per rfc 822 is also performed, based on the length in len.
*
* Return value: The encoded address.
**/
char *
-camel_internet_address_encode_address(const char *real, const char *addr)
+camel_internet_address_encode_address(int *inlen, const char *real, const char *addr)
{
char *name = header_encode_phrase(real);
- char *ret = NULL;
+ char *ret = NULL, *addra = NULL;
+ int len = *inlen;
+ GString *out = g_string_new("");
g_assert(addr);
+ if (name && name[0]) {
+ if (strlen(name) + len > CAMEL_FOLD_SIZE) {
+ char *folded = header_fold(name, len);
+ char *last;
+ g_string_append(out, folded);
+ g_free(folded);
+ last = strrchr(out->str, '\n');
+ if (last)
+ len = last-(out->str+out->len);
+ else
+ len = out->len;
+ } else {
+ g_string_append(out, name);
+ len += strlen(name);
+ }
+ addr = addra = g_strdup_printf("<%s>", addr);
+ }
+
+ /* NOTE: Strictly speaking, we could and should split the
+ * internal address up if we need to, on atom or specials
+ * boundaries - however, to aid interoperability with mailers
+ * that will probably not handle this case, we will just move
+ * the whole address to its own line */
+ if (strlen(addr) + len > CAMEL_FOLD_SIZE) {
+ g_string_append(out, "\n\t");
+ g_string_append(out, addr);
+ len = strlen(addr)+1;
+ } else {
+ g_string_append(out, addr);
+ len += strlen(addr);
+ }
+
+ *inlen = len;
+#if 0
if (name && name[0])
ret = g_strdup_printf("%s <%s>", name, addr);
else
ret = g_strdup_printf("%s", addr);
-
+#endif
g_free(name);
+ g_free(addra);
+
+ ret = out->str;
+ g_string_free(out, FALSE);
return ret;
}