summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Roessler <roessler@does-not-exist.org>1999-07-20 09:38:07 +0000
committerThomas Roessler <roessler@does-not-exist.org>1999-07-20 09:38:07 +0000
commita71df9dc6c7ee61b7259ec7ab3b50787f96d90b4 (patch)
tree6c6283135ea82cfdd7d25c9a1a0a000ade83249c
parentd0b3c76ae7658317eefe99de8b281d80ad36bc02 (diff)
As Aaron Schrab noted, patch-0.95.6.tlr.reverse_name.1 broke the use
of my_hdr from send-hooks. This patch introduces a new variable $from which can be used to use a default sender address; to make this possible, a new variable class DT_ADDR is defined. We now have the following algorithm for determining the from address: - $from is used as the default from address, if defined. Otherwise, the local user name and (if the user wishes so) the local domain are used. - This address can be overridden by $reverse_name, if set. - Now, send-hooks are evaluated. - Afterwards, user headers are evaluated. In this step, the from header can be overridden using my_hdr From:. - When there is no real name, $realname is used for it. Note that, when the default from header is used and $from defines a real name, it takes precedence over $realname.
-rw-r--r--alias.c9
-rw-r--r--globals.h2
-rw-r--r--init.c29
-rw-r--r--init.h2
-rw-r--r--send.c52
5 files changed, 57 insertions, 37 deletions
diff --git a/alias.c b/alias.c
index c37f93ee..9f1afab1 100644
--- a/alias.c
+++ b/alias.c
@@ -420,11 +420,14 @@ int mutt_addr_is_user (ADDRESS *addr)
if (mutt_strcasecmp (addr->mailbox, Username) == 0)
return 1;
- if(string_is_address(addr->mailbox, Username, Hostname))
+ if (string_is_address(addr->mailbox, Username, Hostname))
return 1;
- if(string_is_address(addr->mailbox, Username, mutt_fqdn(0)))
+ if (string_is_address(addr->mailbox, Username, mutt_fqdn(0)))
return 1;
- if(string_is_address(addr->mailbox, Username, mutt_fqdn(1)))
+ if (string_is_address(addr->mailbox, Username, mutt_fqdn(1)))
+ return 1;
+
+ if (From && !mutt_strcasecmp (From->mailbox, addr->mailbox))
return 1;
if (Alternates.pattern &&
diff --git a/globals.h b/globals.h
index a48b84ee..ebc1e5df 100644
--- a/globals.h
+++ b/globals.h
@@ -26,6 +26,8 @@ WHERE char Errorbuf[SHORT_STRING];
WHERE char *MuttDotlock;
#endif
+WHERE ADDRESS *From;
+
WHERE char *AliasFile;
WHERE char *AliasFmt;
WHERE char *AttachSep;
diff --git a/init.c b/init.c
index 17405b8e..84aa95aa 100644
--- a/init.c
+++ b/init.c
@@ -646,6 +646,13 @@ static void mutt_restore_default (struct option_t *p)
*((char **) p->data) = safe_strdup (path);
}
break;
+ case DT_ADDR:
+ if (p->init)
+ {
+ rfc822_free_address ((ADDRESS **) p->data);
+ *((ADDRESS **) p->data) = rfc822_parse_adrlist (NULL, (char *) p->init);
+ }
+ break;
case DT_BOOL:
if (p->init)
set_option (p->data);
@@ -814,7 +821,8 @@ static int parse_set (BUFFER *tmp, BUFFER *s, unsigned long data, BUFFER *err)
set_option (MuttVars[idx].data);
}
else if (DTYPE (MuttVars[idx].type) == DT_STR ||
- DTYPE (MuttVars[idx].type) == DT_PATH)
+ DTYPE (MuttVars[idx].type) == DT_PATH ||
+ DTYPE (MuttVars[idx].type) == DT_ADDR)
{
if (query || *s->dptr != '=')
{
@@ -827,18 +835,26 @@ static int parse_set (BUFFER *tmp, BUFFER *s, unsigned long data, BUFFER *err)
s->dptr++;
/* copy the value of the string */
- FREE (MuttVars[idx].data);
+ if (DTYPE (MuttVars[idx].type) == DT_ADDR)
+ rfc822_free_address ((ADDRESS **) MuttVars[idx].data);
+ else
+ FREE (MuttVars[idx].data);
+
mutt_extract_token (tmp, s, 0);
- if (MuttVars[idx].type == DT_PATH)
+ if (DTYPE (MuttVars[idx].type) == DT_PATH)
{
strfcpy (scratch, tmp->data, sizeof (scratch));
mutt_expand_path (scratch, sizeof (scratch));
*((char **) MuttVars[idx].data) = safe_strdup (scratch);
}
- else
+ else if (DTYPE (MuttVars[idx].type) == DT_STR)
{
*((char **) MuttVars[idx].data) = safe_strdup (tmp->data);
}
+ else
+ {
+ *((ADDRESS **) MuttVars[idx].data) = rfc822_parse_adrlist (NULL, tmp->data);
+ }
}
else if (DTYPE(MuttVars[idx].type) == DT_RX)
{
@@ -1442,6 +1458,11 @@ int mutt_var_value_complete (char *buffer, size_t len, int pos)
(DTYPE(MuttVars[idx].type) == DT_RX))
snprintf(pt, dlen, "%s\"%s\"", tmp,
NONULL (*((char **) MuttVars[idx].data)));
+ else if (DTYPE (MuttVars[idx].type) == DT_ADDR)
+ {
+ *pt = '\0';
+ rfc822_write_address (pt, dlen, *((ADDRESS **) MuttVars[idx].data));
+ }
else if (DTYPE (MuttVars[idx].type) == DT_QUAD)
snprintf(pt, dlen, "%s%s", tmp, vals[quadoption (MuttVars[idx].data)]);
else if (DTYPE (MuttVars[idx].type) == DT_NUM)
diff --git a/init.h b/init.h
index 870dd09f..e968edcd 100644
--- a/init.h
+++ b/init.h
@@ -29,6 +29,7 @@
#define DT_RX 7 /* regular expressions */
#define DT_MAGIC 8 /* mailbox type */
#define DT_SYN 9 /* synonym for another variable */
+#define DT_ADDR 10 /* e-mail address */
#define DTYPE(x) ((x) & DT_MASK)
@@ -121,6 +122,7 @@ struct option_t MuttVars[] = {
{ "forw_format", DT_SYN, R_NONE, UL "forward_format", 0 },
{ "forward_quote", DT_BOOL, R_NONE, OPTFORWQUOTE, 0 },
{ "forw_quote", DT_SYN, R_NONE, UL "forward_quote", 0 },
+ { "from", DT_ADDR, R_NONE, UL &From, UL "" },
{ "hdr_format", DT_SYN, R_NONE, UL "index_format", 0 },
{ "hdrs", DT_BOOL, R_NONE, OPTHDRS, 1 },
{ "header", DT_BOOL, R_NONE, OPTHEADER, 0 },
diff --git a/send.c b/send.c
index c7dda7b2..cc32179c 100644
--- a/send.c
+++ b/send.c
@@ -266,7 +266,13 @@ static void process_user_header (ENVELOPE *env)
for (; uh; uh = uh->next)
{
- if (mutt_strncasecmp ("reply-to:", uh->data, 9) == 0)
+ if (mutt_strncasecmp ("from:", uh->data, 5) == 0)
+ {
+ /* User has specified a default From: address. Remove default address */
+ rfc822_free_address (&env->from);
+ env->from = rfc822_parse_adrlist (env->from, uh->data + 5);
+ }
+ else if (mutt_strncasecmp ("reply-to:", uh->data, 9) == 0)
{
rfc822_free_address (&env->reply_to);
env->reply_to = rfc822_parse_adrlist (env->reply_to, uh->data + 9);
@@ -274,8 +280,7 @@ static void process_user_header (ENVELOPE *env)
else if (mutt_strncasecmp ("to:", uh->data, 3) != 0 &&
mutt_strncasecmp ("cc:", uh->data, 3) != 0 &&
mutt_strncasecmp ("bcc:", uh->data, 4) != 0 &&
- mutt_strncasecmp ("subject:", uh->data, 8) != 0 &&
- mutt_strncasecmp ("from:", uh->data, 5) != 0)
+ mutt_strncasecmp ("subject:", uh->data, 8) != 0)
{
if (last)
{
@@ -289,21 +294,6 @@ static void process_user_header (ENVELOPE *env)
}
}
-static void process_user_from (ENVELOPE *env)
-{
- LIST *uh = UserHeader;
-
- for (; uh; uh = uh->next)
- {
- if (mutt_strncasecmp ("from:", uh->data, 5) == 0)
- {
- rfc822_free_address (&env->from);
- env->from = rfc822_parse_adrlist (env->from, uh->data + 5);
- break;
- }
- }
-}
-
LIST *mutt_copy_list (LIST *p)
{
LIST *t, *r=NULL, *l=NULL;
@@ -795,18 +785,28 @@ static ADDRESS *set_reverse_name (ENVELOPE *env)
static ADDRESS *mutt_default_from (void)
{
- ADDRESS *adr = rfc822_new_address ();
+ ADDRESS *adr;
const char *fqdn = mutt_fqdn(1);
-
- /* don't set realname here, it will be set later */
- if (option (OPTUSEDOMAIN))
+ /*
+ * Note: We let $from override $realname here. Is this the right
+ * thing to do?
+ */
+
+ if (From)
+ adr = rfc822_cpy_adr_real (From);
+ else if (option (OPTUSEDOMAIN))
{
+ adr = rfc822_new_address ();
adr->mailbox = safe_malloc (mutt_strlen (Username) + mutt_strlen (fqdn) + 2);
sprintf (adr->mailbox, "%s@%s", NONULL(Username), NONULL(fqdn));
}
else
+ {
+ adr = rfc822_new_address ();
adr->mailbox = safe_strdup (NONULL(Username));
+ }
+
return (adr);
}
@@ -990,14 +990,6 @@ ci_send_message (int flags, /* send mode */
msg->env->from = set_reverse_name (cur->env);
}
- /*
- * process a my_hdr From: at this point, and don't override
- * reverse_name by it.
- */
-
- if (!msg->env->from && option (OPTHDRS) && !(flags & (SENDPOSTPONED | SENDEDITMSG)))
- process_user_from (msg->env);
-
if (!msg->env->from && option (OPTUSEFROM) && !(flags & (SENDEDITMSG|SENDPOSTPONED)))
msg->env->from = mutt_default_from ();