aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--camel/ChangeLog17
-rw-r--r--camel/camel-internet-address.c56
-rw-r--r--camel/camel-internet-address.h2
-rw-r--r--camel/camel-mime-part.c6
4 files changed, 73 insertions, 8 deletions
diff --git a/camel/ChangeLog b/camel/ChangeLog
index bcdd652f38..5a0d7bfdaf 100644
--- a/camel/ChangeLog
+++ b/camel/ChangeLog
@@ -1,3 +1,20 @@
+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.
+
2001-02-12 Jeffrey Stedfast <fejj@ximian.com>
* providers/local/camel-local-provider.c: mbox, mh, and maildir
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;
}
diff --git a/camel/camel-internet-address.h b/camel/camel-internet-address.h
index 879514c158..7afd74fad9 100644
--- a/camel/camel-internet-address.h
+++ b/camel/camel-internet-address.h
@@ -49,7 +49,7 @@ int camel_internet_address_find_name(CamelInternetAddress *, const char *, con
int camel_internet_address_find_address(CamelInternetAddress *, const char *, const char **);
/* utility functions, for network/display formatting */
-char * camel_internet_address_encode_address(const char *name, const char *addr);
+char * camel_internet_address_encode_address(int *len, const char *name, const char *addr);
char * camel_internet_address_format_address(const char *real, const char *addr);
#endif /* ! _CAMEL_INTERNET_ADDRESS_H */
diff --git a/camel/camel-mime-part.c b/camel/camel-mime-part.c
index a22b96240a..8145bc1675 100644
--- a/camel/camel-mime-part.c
+++ b/camel/camel-mime-part.c
@@ -99,6 +99,10 @@ init_header_name_table()
header_formatted_table = g_hash_table_new(g_strcase_hash, g_strcase_equal);
g_hash_table_insert(header_formatted_table, "Content-Type", (void *)1);
g_hash_table_insert(header_formatted_table, "Content-Disposition", (void *)1);
+ g_hash_table_insert(header_formatted_table, "To", (void *)1);
+ g_hash_table_insert(header_formatted_table, "From", (void *)1);
+ g_hash_table_insert(header_formatted_table, "Cc", (void *)1);
+ g_hash_table_insert(header_formatted_table, "Bcc", (void *)1);
}
static void
@@ -493,7 +497,7 @@ write_to_stream(CamelDataWrapper *data_wrapper, CamelStream *stream)
if (val == NULL) {
g_warning("h->value is NULL here for %s", h->name);
count = 0;
- } else if (g_hash_table_lookup(header_formatted_table, val) == NULL) {
+ } else if (g_hash_table_lookup(header_formatted_table, h->name) == NULL) {
val = header_fold(val, strlen(h->name));
count = camel_stream_printf(stream, "%s%s%s\n", h->name, isspace(val[0]) ? ":" : ": ", val);
g_free(val);