Skip to content

Commit 1fa5cc5

Browse files
committed
Added support for strftime(3) formatting in the append_filename
configuration so allow archived messages to be split over multiple mailboxes (monthly or yearly for example)
1 parent 842dd8b commit 1fa5cc5

File tree

4 files changed

+29
-16
lines changed

4 files changed

+29
-16
lines changed

docs/hmrc.html

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1301,9 +1301,7 @@ <h3><a name="sysmisc" id="sysmisc">System miscellaneous</a></h3>
13011301
<i>append = 1</i></dd>
13021302
<dd><a name="append_filename" id="append_filename"></a></dd>
13031303
<dt><strong>append_filename = [ string ]</strong></dt>
1304-
<dd>Specifies the filename to be used by the append option. $DIR
1305-
may be used to specify a name relative to the directory specified
1306-
in the -d or dir option.<br>
1304+
<dd>Specifies the filename to be used by the append option. $DIR may be used to specify a name relative to the directory specified in the -d or dir option. The string will be passed to strftime(3) to allow splitting the mailbox into yearly or monthy files, such as "%Y-%m.mbox". <br>
13071305
<br>
13081306
<i>append_filename = $DIR/INBOX</i></dd>
13091307
<dd><a name="txtsuffix" id="txtsuffix"></a></dd>

src/Makefile.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ CPPFLAGS=@CPPFLAGS@ @INCLUDES@
4040
YACC=@YACC@
4141
NETLIBS=@LIBS@
4242
LDFLAGS=@LDFLAGS@
43-
MISC_LIBS= -lm -lpcre -ltrio
43+
MISC_LIBS= -lpcre -ltrio -lm
4444
OPT_LIBS=@EXTRA_LIBS@
4545

4646
INCS= domains.h hypermail.h lang.h proto.h \

src/parse.c

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1531,6 +1531,7 @@ int parsemail(char *mbox, /* file name */
15311531
int num, isinheader, hassubject, hasdate;
15321532
int num_added = 0;
15331533
long exp_time = -1;
1534+
time_t curtime;
15341535
time_t delete_older_than = (set_delete_older ? convtoyearsecs(set_delete_older) : 0);
15351536
time_t delete_newer_than = (set_delete_newer ? convtoyearsecs(set_delete_newer) : 0);
15361537
annotation_robot_t annotation_robot = ANNOTATION_ROBOT_NONE;
@@ -1541,6 +1542,8 @@ int parsemail(char *mbox, /* file name */
15411542
int require_filter_len, require_filter_full_len;
15421543
struct hmlist *tlist;
15431544
char filename[MAXFILELEN];
1545+
char directory[MAXFILELEN];
1546+
char pathname[MAXFILELEN];
15441547
struct emailinfo *emp;
15451548
char *att_dir = NULL; /* directory name to store attachments in */
15461549
char *meta_dir = NULL; /* directory name where we're storing the meta data
@@ -1655,21 +1658,31 @@ int parsemail(char *mbox, /* file name */
16551658
if(set_append) {
16561659

16571660
/* add to an mbox as we read */
1658-
1659-
if(set_append_filename && strncmp(set_append_filename, "$DIR/", 5)) {
1660-
if(strlen(set_append_filename) >= sizeof(filename))
1661-
progerr("append_filename too long");
1662-
strcpy(filename, set_append_filename);
1661+
*directory = 0;
1662+
*filename = 0;
1663+
*pathname = 0;
1664+
if (set_append_filename) {
1665+
time(&curtime);
1666+
if(strncmp(set_append_filename, "$DIR/", 5) == 0) {
1667+
strncpy(directory, dir, MAXFILELEN - 1);
1668+
strftime(filename, MAXFILELEN - 1, set_append_filename+5,
1669+
localtime(&curtime));
1670+
} else {
1671+
strftime(filename, MAXFILELEN - 1, set_append_filename,
1672+
localtime(&curtime));
1673+
}
1674+
} else {
1675+
strncpy(directory, dir, MAXFILELEN - 1);
1676+
strncpy(filename, "mbox", MAXFILELEN - 1);
16631677
}
1664-
else if(trio_snprintf(filename, sizeof(filename), "%s%s", dir,
1665-
set_append_filename ? set_append_filename + 5
1666-
: "mbox")
1667-
== sizeof(filename)) {
1678+
1679+
if(trio_snprintf(pathname, sizeof(pathname), "%s%s", directory,
1680+
filename) == sizeof(pathname)) {
16681681
progerr("Can't build mbox filename");
16691682
}
1670-
if(!(fpo = fopen(filename, "a"))) {
1683+
if(!(fpo = fopen(pathname, "a"))) {
16711684
trio_snprintf(errmsg, sizeof(errmsg), "%s \"%s\".",
1672-
lang[MSG_CANNOT_OPEN_MAIL_ARCHIVE], filename);
1685+
lang[MSG_CANNOT_OPEN_MAIL_ARCHIVE], pathname);
16731686
progerr(errmsg);
16741687
}
16751688
}

src/setup.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,9 @@ struct Config cfg[] = {
412412
{"append_filename", &set_append_filename, NULL, CFG_STRING,
413413
"# Specifies the filename to be used by the append option.\n"
414414
"# $DIR may be used to specify a name relative to the directory\n"
415-
"# specified in the -d or dir option.\n", FALSE},
415+
"# specified in the -d or dir option.\n"
416+
"# The string will be passed to strftime(3) to allow splitting the\n"
417+
"# mailbox into yearly or monthy files, such as \"%Y-%m.mbox\".\n" , FALSE},
416418

417419
{"nonsequential", &set_nonsequential, BFALSE, CFG_SWITCH,
418420
"# Set this to On to generate filenames that are not sequential, but\n"

0 commit comments

Comments
 (0)