(compose_header_set): Check for valid arguments at
the beginning of the function (value can be NULL, e.g. if the user hit C-D at Cc: prompt). Call util_merge_addresses() only if inplacealiases is set. Expand aliases before calling it.
Showing
1 changed file
with
39 additions
and
9 deletions
1 | /* GNU Mailutils -- a suite of utilities for electronic mail | 1 | /* GNU Mailutils -- a suite of utilities for electronic mail |
2 | Copyright (C) 1999, 2001, 2002, 2003, 2004, | 2 | Copyright (C) 1999, 2001, 2002, 2003, 2004, |
3 | 2005 Free Software Foundation, Inc. | 3 | 2005, 2006 Free Software Foundation, Inc. |
4 | 4 | ||
5 | GNU Mailutils is free software; you can redistribute it and/or modify | 5 | GNU Mailutils is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published by | 6 | it under the terms of the GNU General Public License as published by |
... | @@ -221,6 +221,9 @@ compose_header_set (compose_env_t * env, char *name, char *value, int mode) | ... | @@ -221,6 +221,9 @@ compose_header_set (compose_env_t * env, char *name, char *value, int mode) |
221 | int status; | 221 | int status; |
222 | char *old_value; | 222 | char *old_value; |
223 | 223 | ||
224 | if (!value || value[0] == 0) | ||
225 | return EINVAL; | ||
226 | |||
224 | if (!env->header | 227 | if (!env->header |
225 | && (status = mu_header_create (&env->header, NULL, 0, NULL)) != 0) | 228 | && (status = mu_header_create (&env->header, NULL, 0, NULL)) != 0) |
226 | { | 229 | { |
... | @@ -232,23 +235,50 @@ compose_header_set (compose_env_t * env, char *name, char *value, int mode) | ... | @@ -232,23 +235,50 @@ compose_header_set (compose_env_t * env, char *name, char *value, int mode) |
232 | { | 235 | { |
233 | case COMPOSE_REPLACE: | 236 | case COMPOSE_REPLACE: |
234 | case COMPOSE_APPEND: | 237 | case COMPOSE_APPEND: |
235 | status = mu_header_set_value (env->header, name, value, mode); | 238 | if (is_address_field (name) |
239 | && util_getenv (NULL, "inplacealiases", Mail_env_boolean, 0) == 0) | ||
240 | { | ||
241 | char *exp = alias_expand (value); | ||
242 | status = mu_header_set_value (env->header, name, exp ? exp : value, | ||
243 | mode); | ||
244 | free (exp); | ||
245 | } | ||
246 | else | ||
247 | status = mu_header_set_value (env->header, name, value, mode); | ||
236 | break; | 248 | break; |
237 | 249 | ||
238 | case COMPOSE_SINGLE_LINE: | 250 | case COMPOSE_SINGLE_LINE: |
239 | if (!value || value[0] == 0) | ||
240 | return EINVAL; | ||
241 | |||
242 | if (mu_header_aget_value (env->header, name, &old_value) == 0 | 251 | if (mu_header_aget_value (env->header, name, &old_value) == 0 |
243 | && old_value[0]) | 252 | && old_value[0]) |
244 | { | 253 | { |
245 | status = util_merge_addresses (&old_value, value); | 254 | if (is_address_field (name) |
246 | if (status == 0) | 255 | && util_getenv (NULL, "inplacealiases", Mail_env_boolean, 0) == 0) |
247 | status = mu_header_set_value (env->header, name, old_value, 1); | 256 | { |
257 | char *exp = alias_expand (value); | ||
258 | status = util_merge_addresses (&old_value, exp ? exp : value); | ||
259 | if (status == 0) | ||
260 | status = mu_header_set_value (env->header, name, old_value, 1); | ||
261 | free (exp); | ||
262 | } | ||
263 | else | ||
264 | { | ||
265 | size_t size = strlen (old_value) + strlen (value) + 2; | ||
266 | char *p = realloc (old_value, size); | ||
267 | if (!p) | ||
268 | status = ENOMEM; | ||
269 | else | ||
270 | { | ||
271 | old_value = p; | ||
272 | strcat (old_value, ","); | ||
273 | strcat (old_value, value); | ||
274 | status = mu_header_set_value (env->header, name, old_value, | ||
275 | 1); | ||
276 | } | ||
277 | } | ||
248 | free (old_value); | 278 | free (old_value); |
249 | } | 279 | } |
250 | else | 280 | else |
251 | status = mu_header_set_value (env->header, name, value, 1); | 281 | status = compose_header_set (env, name, value, COMPOSE_REPLACE); |
252 | } | 282 | } |
253 | 283 | ||
254 | return status; | 284 | return status; | ... | ... |
-
Please register or sign in to post a comment