summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2021-06-10 09:34:44 +0300
committerSergey Poznyakoff <gray@gnu.org>2021-06-10 09:50:00 +0300
commitdbbc3a3db2e7adbeb903722ba11ff9e4d6dc3893 (patch)
tree1d4cbacbdec2ddd075470ad5f3d887202aa3e7ef
parent572ead443051b2851cfdce12156c7e5418821ff2 (diff)
downloadmailutils-dbbc3a3db2e7adbeb903722ba11ff9e4d6dc3893.tar.gz
mailutils-dbbc3a3db2e7adbeb903722ba11ff9e4d6dc3893.tar.bz2
Provide several ways of creating the outgoing file name.
Several mail commands store message in a file named by its recipient (or sender) in the "folder" directory (these commands are: Copy, Save, Mail, followup, Followup). As per POSIX, the local part of the email address serves as the file name. There may be cases, however, when using the entire email would be preferable. This commit introduces new mail variable "outfilename" that controls how the file name is generated. Its default value is "local", which means use the email local part. Other possible values are: "email", to save messages in a file named by entire email, and "domain", to save them in a file named by domain part of the email. * NEWS: Document changes. * doc/texinfo/programs/mail.texi: Document changes. * mail/mail.c (default_setup): Set outfilename=local. * mail/mail.h (mailvar_name_outfilename): New define. (outfilename_mode): New extern. (util_outfilename): New proto. * mail/mailvar.c: New variable: "outfilename". * mail/send.c (mail_compose_send): Use util_outfilename to form outgoing file name. * mail/util.c (outfilename_mode): New global. (util_outfilename): New function. (util_message_sender): Use util_outfilename.
-rw-r--r--NEWS12
-rw-r--r--doc/texinfo/programs/mail.texi27
-rw-r--r--mail/mail.c1
-rw-r--r--mail/mail.h11
-rw-r--r--mail/mailvar.c33
-rw-r--r--mail/send.c8
-rw-r--r--mail/util.c62
7 files changed, 130 insertions, 24 deletions
diff --git a/NEWS b/NEWS
index fb9853952..480740b0b 100644
--- a/NEWS
+++ b/NEWS
@@ -1,4 +1,4 @@
-GNU mailutils NEWS -- history of user-visible changes. 2021-06-09
+GNU mailutils NEWS -- history of user-visible changes. 2021-06-10
See the end of file for copying conditions.
Please send mailutils bug reports to <bug-mailutils@gnu.org>.
@@ -42,6 +42,16 @@ deprecated. Use 'retry-sleep' instead.
- fullnames
Controls whether personal parts of emails are preserved in
recipient addresses when replying. Default is true.
+ - outfilename
+ Defines the algorithm to convert the recipient email to the
+ name of the file used to record outgoing messages to that
+ recipient. This affects the following commands: Copy,
+ Save, Mail, followup, and Followup. This is a string variable,
+ that can take one of the following values:
+ "local" - Local part of the email address is taken as the
+ file name. This is the default.
+ "email" - Entire email is takes as the file name.
+ "domain" - Domain part of the email is used as the file name.
Version 3.12, 2021-02-13
diff --git a/doc/texinfo/programs/mail.texi b/doc/texinfo/programs/mail.texi
index ff947a558..dacecad56 100644
--- a/doc/texinfo/programs/mail.texi
+++ b/doc/texinfo/programs/mail.texi
@@ -2217,6 +2217,7 @@ Unsetting this variable tells @command{mail} to obtain it from the
@item fullnames
@*Type: Boolean.
@*Default: True.
+@vrindex fullnames, mail variable
Preserve personal parts (comments) of recipient addresses when replying to a
message.
@@ -2622,6 +2623,30 @@ Unsetting this variable disables the warning.
This variable is not used. It exists for compatibility with other
@command{mailx} implementations and for future use.
+@kwindex outfilename
+@item outfilename
+@*Type: Three-state: @samp{local}, @samp{email}, @samp{domain}.
+@*Default: @samp{local}
+@vrindex outfilename, mail variable
+
+Defines the algorithm to convert the recipient email to the name of
+the file used to record outgoing messages to that recipient. This
+affects the following commands: @code{Copy}, @code{Save}, @code{Mail},
+@code{followup}, and @code{Followup}. The following values are allowed:
+
+@table @code
+@item local
+Local part of the email address is taken as the file name. This is
+the default.
+
+@item email
+Entire email is takes as the file name.
+
+@item domain
+
+Domain part of the email is used as the file name.
+@end table
+
@kwindex outfolder
@item outfolder
@*Type: Boolean or String.
@@ -2635,7 +2660,7 @@ to be located in the directory specified by the @code{folder} variable
If string, its value names the directory where to store these files.
This variable affects the following commands: @code{Copy},
-@code{Save}, @code{Mail}, @code{Reply}, and @code{Followup}.
+@code{Save}, @code{Mail}, @code{followup}, and @code{Followup}.
@kwindex PID
@item PID
diff --git a/mail/mail.c b/mail/mail.c
index 1b88bbf5f..4159e85d6 100644
--- a/mail/mail.c
+++ b/mail/mail.c
@@ -403,6 +403,7 @@ static char *default_setup[] = {
"set headline=\"%>%a%4m %18f %16d %3L/%-5o %s\"",
"unset folder",
"set fullnames",
+ "set outfilename=local",
/* Start in mail reading mode */
"setq mode=read",
diff --git a/mail/mail.h b/mail/mail.h
index 19971d4d8..fec644197 100644
--- a/mail/mail.h
+++ b/mail/mail.h
@@ -199,6 +199,7 @@ struct mailvar_variable
#define mailvar_name_mode "mode"
#define mailvar_name_nullbody "nullbody"
#define mailvar_name_nullbodymsg "nullbodymsg"
+#define mailvar_name_outfilename "outfilename"
#define mailvar_name_outfolder "outfolder"
#define mailvar_name_page "page"
#define mailvar_name_prompt "prompt"
@@ -421,6 +422,15 @@ msgset_str (const msgset_t *set)
return mu_coord_string (set->crd);
}
+/* Constants for naming outgoing mail files */
+enum
+ {
+ outfilename_local, /* File is named by local part of the recipient email. */
+ outfilename_email, /* File is named by entire email. */
+ outfilename_domain /* File is named by domain part. */
+ };
+extern int outfilename_mode;
+
#define MDHINT_SELECTED_HEADERS 0x1
struct mime_descend_closure
@@ -496,6 +506,7 @@ void util_slist_remove (mu_list_t *list, char *value);
void util_slist_destroy (mu_list_t *list);
char *util_slist_to_string (mu_list_t list, const char *delim);
void util_strcat (char **dest, const char *str);
+char *util_outfilename (mu_address_t addr);
char *util_outfolder_name (char *str);
void util_save_outgoing (mu_message_t msg, char *savefile);
int util_error_range (size_t msgno);
diff --git a/mail/mailvar.c b/mail/mailvar.c
index 28a4d4b44..7a6435f29 100644
--- a/mail/mailvar.c
+++ b/mail/mailvar.c
@@ -15,6 +15,7 @@
along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */
#include "mail.h"
+#include "mailutils/kwd.h"
#define MAILVAR_ALIAS 0x0001
#define MAILVAR_RDONLY 0x0002
@@ -52,6 +53,8 @@ static int set_folder (enum mailvar_cmd cmd,
struct mailvar_variable *);
static int set_headline (enum mailvar_cmd,
struct mailvar_variable *);
+static int set_outfilename (enum mailvar_cmd,
+ struct mailvar_variable *);
struct mailvar_symbol mailvar_tab[] =
{
@@ -293,6 +296,11 @@ struct mailvar_symbol mailvar_tab[] =
MAILVAR_TYPEMASK (mailvar_type_boolean),
N_("when replying, preserve personal parts of recipient emails") },
+ { { mailvar_name_outfilename },
+ MAILVAR_TYPEMASK (mailvar_type_string),
+ N_("how to create outgoing file name: local, domain, email"),
+ set_outfilename },
+
{ { mailvar_name_PID },
MAILVAR_TYPEMASK (mailvar_type_string) | MAILVAR_RDONLY,
N_("PID of this process") },
@@ -735,6 +743,31 @@ set_debug (enum mailvar_cmd cmd, struct mailvar_variable *var)
return 0;
}
+static int
+set_outfilename (enum mailvar_cmd cmd, struct mailvar_variable *var)
+{
+ static struct mu_kwd kwtab[] = {
+ { "local", outfilename_local },
+ { "email", outfilename_email },
+ { "domain", outfilename_domain },
+ { NULL }
+ };
+
+ switch (cmd)
+ {
+ case mailvar_cmd_set:
+ if (mu_kwd_xlat_name (kwtab, var->value.string, &outfilename_mode))
+ {
+ mu_error (_("unsupported value for %s"), var->name);
+ return 1;
+ }
+ break;
+
+ default:
+ return 1;
+ }
+ return 0;
+}
size_t
_mailvar_symbol_count (int set)
diff --git a/mail/send.c b/mail/send.c
index 556012bff..029fbf432 100644
--- a/mail/send.c
+++ b/mail/send.c
@@ -1427,14 +1427,8 @@ mail_compose_send (compose_env_t *env, int save_to)
struct mu_address hint = MU_ADDRESS_HINT_INITIALIZER;
mu_address_create_hint (&addr, rcpt, &hint, 0);
- mu_address_aget_email (addr, 1, &savefile);
+ savefile = util_outfilename (addr);
mu_address_destroy (&addr);
- if (savefile)
- {
- char *p = strchr (savefile, '@');
- if (p)
- *p = 0;
- }
}
}
util_save_outgoing (msg, savefile);
diff --git a/mail/util.c b/mail/util.c
index 214b89f85..0f2a748a2 100644
--- a/mail/util.c
+++ b/mail/util.c
@@ -486,11 +486,54 @@ util_folder_path (const char *name)
return folder;
}
+int outfilename_mode;
+
+char *
+util_outfilename (mu_address_t addr)
+{
+ char *buf, *p;
+ int rc;
+
+ if ((rc = mu_address_aget_email (addr, 1, &buf)) != 0)
+ {
+ mu_error (_("Cannot determine sender name: %s"), mu_strerror (rc));
+ return NULL;
+ }
+
+ switch (outfilename_mode)
+ {
+ case outfilename_local:
+ p = strchr (buf, '@');
+ if (p)
+ *p = 0;
+ break;
+
+ case outfilename_email:
+ break;
+
+ case outfilename_domain:
+ p = strchr (buf, '@');
+ if (p)
+ {
+ p++;
+ memmove (buf, p, strlen (p) + 1);
+ }
+ else
+ {
+ free (buf);
+ buf = mu_strdup ("localdomain");
+ }
+ break;
+ }
+ return buf;
+}
+
char *
util_message_sender (mu_message_t msg, int strip)
{
mu_address_t addr = get_sender_address (msg);
char *buf;
+ int rc;
if (!addr)
{
@@ -507,23 +550,12 @@ util_message_sender (mu_message_t msg, int strip)
if (strip)
{
- char *p;
- if (mu_address_aget_email (addr, 1, &buf) || !buf)
- {
- mu_error (_("Cannot determine sender name"));
- mu_address_destroy (&addr);
- return NULL;
- }
-
- p = strchr (buf, '@');
- if (p)
- *p = 0;
+ buf = util_outfilename (addr);
}
- else if (mu_address_aget_printable (addr, &buf) || !buf)
+ else if ((rc = mu_address_aget_printable (addr, &buf)) != 0)
{
- mu_error (_("Cannot determine sender name"));
- mu_address_destroy (&addr);
- return NULL;
+ mu_error (_("Cannot determine sender name: %s"), mu_strerror (rc));
+ buf = NULL;
}
mu_address_destroy (&addr);

Return to:

Send suggestions and report system problems to the System administrator.