Commit aa02b2ec aa02b2ecffe339a8a3573b41a360c31eb450637f by Sergey Poznyakoff

(concat,strip_message_id,get_msgid_header): Removed

(make_in_reply_to,make_references): Rewritten using new rfc2822 functions.
1 parent e6b45504
Showing 1 changed file with 13 additions and 135 deletions
......@@ -17,148 +17,25 @@
#include "mail.h"
#define DATEBUFSIZE 128
static char *
concat (const char *s1, const char *s2)
{
int len = (s1 ? strlen (s1) : 0) + (s2 ? strlen (s2) : 0) + 2;
char *s = malloc (len);
if (s)
{
char *p = s;
if (s1)
{
strcpy (p, s1);
p += strlen (s1);
*p++ = ' ';
}
if (s2)
strcpy (p, s2);
}
return s;
}
void
make_in_reply_to (compose_env_t *env, message_t msg)
{
char *value, *s1 = NULL, *s2 = NULL;
header_t hdr;
if (message_get_header (msg, &hdr))
return;
if (header_aget_value (hdr, MU_HEADER_DATE, &value))
{
envelope_t envelope = NULL;
value = malloc (DATEBUFSIZE);
if (value)
{
message_get_envelope (msg, &envelope);
envelope_date (envelope, value, DATEBUFSIZE, NULL);
}
}
if (value)
asprintf (&s1, _("Your message of %s"), value);
if (header_aget_value (hdr, MU_HEADER_MESSAGE_ID, &value) == 0)
{
asprintf (&s2, "\n\t%s", value);
free (value);
}
if (s1 || s2)
{
value = concat (s1, s2);
free (s1);
free (s2);
compose_header_set (env, MU_HEADER_IN_REPLY_TO, value,
COMPOSE_REPLACE);
free (value);
}
}
int
strip_message_id (char *msgid, char **val)
{
address_t addr;
char *p = strchr (msgid, '<');
if (!p)
p = msgid;
if (address_create (&addr, p) == 0)
{
size_t count = 0;
char *p;
address_get_count (addr, &count);
if (count != 1)
{
address_destroy (&addr);
return 1;
}
if (address_aget_email (addr, 1, &p))
return -1;
address_destroy (&addr);
*val = malloc (strlen (p) + 3);
if (!*val)
{
free (p);
return -1;
}
sprintf (*val, "<%s>", p);
free (p);
return 0;
}
return 1;
}
char *value = NULL;
int
get_msgid_header (header_t hdr, const char *name, char **val)
{
char *p;
int status = header_aget_value (hdr, name, &p);
if (status)
return status;
status = strip_message_id (p, val);
free (p);
return status;
mu_rfc2822_in_reply_to (msg, &value);
compose_header_set (env, MU_HEADER_IN_REPLY_TO, value,
COMPOSE_REPLACE);
free (value);
}
/* rfc2822:
The "References:" field will contain the contents of the parent's
"References:" field (if any) followed by the contents of the parent's
"Message-ID:" field (if any). If the parent message does not contain
a "References:" field but does have an "In-Reply-To:" field
containing a single message identifier, then the "References:" field
will contain the contents of the parent's "In-Reply-To:" field
followed by the contents of the parent's "Message-ID:" field (if
any). If the parent has none of the "References:", "In-Reply-To:",
or "Message-ID:" fields, then the new message will have no
References:" field. */
void
make_references (compose_env_t *env, message_t msg)
{
char *ref = NULL, *msgid = NULL;
header_t hdr;
if (message_get_header (msg, &hdr))
return;
get_msgid_header (hdr, MU_HEADER_MESSAGE_ID, &msgid);
if (get_msgid_header (hdr, MU_HEADER_REFERENCES, &ref))
get_msgid_header (hdr, MU_HEADER_IN_REPLY_TO, &ref);
char *value = NULL;
if (ref || msgid)
{
char *s = concat (ref, msgid);
free (ref);
free (msgid);
compose_header_set (env, MU_HEADER_REFERENCES, s, COMPOSE_REPLACE);
}
mu_rfc2822_references (msg, &value);
compose_header_set (env, MU_HEADER_REFERENCES, value, COMPOSE_REPLACE);
free (value);
}
/*
......@@ -176,11 +53,14 @@ reply0 (msgset_t *mspec, message_t msg, void *data)
int status;
char *str;
cursor = mspec->msg_part[0];
compose_init (&env);
message_get_header (msg, &hdr);
compose_header_set (&env, MU_HEADER_TO, util_get_sender (mspec->msg_part[0], 0),
compose_header_set (&env, MU_HEADER_TO,
util_get_sender (mspec->msg_part[0], 0),
COMPOSE_SINGLE_LINE);
if (*(int*) data) /* reply starts with a lowercase */
......@@ -240,8 +120,6 @@ reply0 (msgset_t *mspec, message_t msg, void *data)
status = mail_send0 (&env, 0);
compose_destroy (&env);
cursor = mspec->msg_part[0];
return status;
}
......