1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322
|
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 1999-2025 Free Software Foundation, Inc.
GNU Mailutils is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
GNU Mailutils is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */
#include "mail.h"
void
make_in_reply_to (compose_env_t *env, mu_message_t msg)
{
char *value = NULL;
mu_rfc2822_in_reply_to (msg, &value);
compose_header_set (env, MU_HEADER_IN_REPLY_TO, value,
COMPOSE_REPLACE);
free (value);
}
void
make_references (compose_env_t *env, mu_message_t msg)
{
char *value = NULL;
mu_rfc2822_references (msg, &value);
compose_header_set (env, MU_HEADER_REFERENCES, value, COMPOSE_REPLACE);
free (value);
}
/*
* r[eply] [message]
* r[espond] [message]
* Reply to all recipients of the message. Save to record.
* reply_all = 1, send_to = 0
* R[eply] [msglist]
* R[espond] [msglist]
* Reply to the sender of each message in msglist. Save to record.
* reply_all = 0, send_to = 0
* fo[llowup] message
* Reply to all recipients of the message. Save by name.
* reply_all = 1, send_to = 1
* F[ollowup] msglist
* Reply to the sender of each message in msglist. Save by name.
* reply_all = 0, send_to = 1
*/
static void
compose_set_address (compose_env_t *env, char const *hname, char const *input)
{
struct mu_address hint = MU_ADDRESS_HINT_INITIALIZER;
mu_address_t iaddr, oaddr = NULL, ap;
char *result = NULL;
if (mu_address_create_hint (&iaddr, input, &hint, 0))
result = mu_strdup (input);
else
{
for (ap = iaddr; ap; ap = ap->next)
{
const char *email;
if (mu_address_sget_email (ap, 1, &email) || email == NULL)
continue;
if (!(mailvar_is_true (mailvar_name_metoo) &&
mail_is_my_name (email)))
mu_address_union (&oaddr, ap);
}
mu_address_destroy (&iaddr);
mu_address_aget_printable (oaddr, &result);
mu_address_destroy (&oaddr);
}
if (result && result[0])
{
compose_header_set (env, hname, result, COMPOSE_SINGLE_LINE);
free (result);
}
}
static void
compose_remove_personal (compose_env_t *env, char *hname)
{
char const *value;
value = compose_header_get (env, hname, NULL);
if (value)
{
mu_address_t addr = NULL, ap;
struct mu_address hint = MU_ADDRESS_HINT_INITIALIZER;
char *result;
mu_address_create_hint (&addr, value, &hint, 0);
for (ap = addr; ap; ap = ap->next)
{
free (ap->printable);
ap->printable = NULL;
free (ap->comments);
ap->comments = NULL;
free (ap->personal);
ap->personal = NULL;
free (ap->route);
ap->route = NULL;
}
mu_address_aget_printable (addr, &result);
compose_header_set (env, hname, result, COMPOSE_REPLACE);
free (result);
mu_address_destroy (&addr);
}
}
/*
* r[eply] [message]
* r[espond] [message]
* fo[llowup] message
*
* Reply to all recipients of a single message
*/
int
respond_all (int argc, char **argv, int record_sender)
{
int status;
compose_env_t env;
mu_message_t msg;
mu_header_t hdr;
char const *str;
char *p;
msgset_t *msgset = NULL;
if (msgset_parse (argc, argv, MSG_NODELETED, &msgset))
return 1;
if (msgset->next)
{
mu_error (_("Can't reply to multiple messages at once"));
status = 1;
}
else if (util_get_message (mbox, msgset_msgno (msgset), &msg))
{
status = 1;
}
else
{
set_cursor (msgset_msgno (msgset));
mu_message_get_header (msg, &hdr);
compose_init (&env);
p = util_message_sender (msg, 0);
if (p)
{
compose_set_address (&env, MU_HEADER_TO, p);
free (p);
}
/* Add the rest of recipients */
if (mu_header_sget_value (hdr, MU_HEADER_TO, &str) == 0)
{
compose_set_address (&env, MU_HEADER_TO, str);
}
if (mu_header_sget_value (hdr, MU_HEADER_CC, &str) == 0)
{
compose_set_address (&env, MU_HEADER_CC, str);
}
/* Add header line */
//FIXME: decode
if (mu_header_aget_value (hdr, MU_HEADER_SUBJECT, &p) == 0)
{
char *subj = NULL;
if (mu_unre_subject (p, NULL))
util_strcat (&subj, util_reply_prefix ());
util_strcat (&subj, p);
free (p);
compose_header_set (&env, MU_HEADER_SUBJECT, subj, COMPOSE_REPLACE);
free (subj);
}
else
compose_header_set (&env, MU_HEADER_SUBJECT, "", COMPOSE_REPLACE);
if (!mailvar_is_true (mailvar_name_fullnames))
{
compose_remove_personal (&env, MU_HEADER_TO);
compose_remove_personal (&env, MU_HEADER_CC);
}
mu_printf ("To: %s\n", compose_header_get (&env, MU_HEADER_TO, ""));
str = compose_header_get (&env, MU_HEADER_CC, NULL);
if (str)
mu_printf ("Cc: %s\n", str);
mu_printf ("Subject: %s\n\n",
compose_header_get (&env, MU_HEADER_SUBJECT, ""));
make_in_reply_to (&env, msg);
make_references (&env, msg);
status = mail_compose_send (&env, record_sender);
compose_destroy (&env);
util_mark_read (msg);
}
msgset_free (msgset);
return status;
}
/*
* R[eply] [msglist]
* R[espond] [msglist]
* F[ollowup] msglist
*
* Reply to the sender of each message in msglist.
*/
int
respond_msg (int argc, char **argv, int record_sender)
{
mu_message_t msg;
mu_header_t hdr;
compose_env_t env;
int status;
char *p;
char const *str;
msgset_t *msgset = NULL, *mp;
if (msgset_parse (argc, argv, MSG_NODELETED, &msgset))
return 1;
if (util_get_message (mbox, msgset_msgno (msgset), &msg))
{
status = 1;
}
else
{
size_t last;
set_cursor (msgset_msgno (msgset));
mu_message_get_header (msg, &hdr);
compose_init (&env);
for (mp = msgset; mp; mp = mp->next)
{
mu_message_t mesg;
last = msgset_msgno (mp);
if (util_get_message (mbox, last, &mesg) == 0)
{
p = util_message_sender (mesg, 0);
if (p)
{
compose_set_address (&env, MU_HEADER_TO, p);
free (p);
}
util_mark_read (mesg);
}
}
/* Add subject header */
if (mu_header_aget_value (hdr, MU_HEADER_SUBJECT, &p) == 0)
{
char *subj = NULL;
if (mu_unre_subject (p, NULL))
util_strcat (&subj, util_reply_prefix ());
util_strcat (&subj, p);
free (p);
compose_header_set (&env, MU_HEADER_SUBJECT, subj, COMPOSE_REPLACE);
free (subj);
}
else
compose_header_set (&env, MU_HEADER_SUBJECT, "", COMPOSE_REPLACE);
if (!mailvar_is_true (mailvar_name_fullnames))
{
compose_remove_personal (&env, MU_HEADER_TO);
compose_remove_personal (&env, MU_HEADER_CC);
}
mu_printf ("To: %s\n", compose_header_get (&env, MU_HEADER_TO, ""));
str = compose_header_get (&env, MU_HEADER_CC, NULL);
if (str)
mu_printf ("Cc: %s\n", str);
mu_printf ("Subject: %s\n\n",
compose_header_get (&env, MU_HEADER_SUBJECT, ""));
make_in_reply_to (&env, msg);
make_references (&env, msg);
status = mail_compose_send (&env, record_sender);
compose_destroy (&env);
set_cursor (last);
}
msgset_free (msgset);
return status;
}
int
mail_reply (int argc, char **argv)
{
int all = mu_islower (argv[0][0]);
if (mailvar_is_true (mailvar_name_flipr))
all = !all;
return (all ? respond_all : respond_msg) (argc, argv, 0);
}
int
mail_followup (int argc, char **argv)
{
int all = mu_islower (argv[0][0]);
return (all ? respond_all : respond_msg) (argc, argv, 1);
}
|