Skip to content

Commit 1aa0169

Browse files
authored
Merge pull request #73 from oz-djh/multi-append-file
Added support for strftime(3) formatting in the append_filename
2 parents f941bec + 1fa5cc5 commit 1aa0169

File tree

3 files changed

+28
-15
lines changed

3 files changed

+28
-15
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/parse.c

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1536,6 +1536,7 @@ int parsemail(char *mbox, /* file name */
15361536
int num, isinheader, hassubject, hasdate;
15371537
int num_added = 0;
15381538
long exp_time = -1;
1539+
time_t curtime;
15391540
time_t delete_older_than = (set_delete_older ? convtoyearsecs(set_delete_older) : 0);
15401541
time_t delete_newer_than = (set_delete_newer ? convtoyearsecs(set_delete_newer) : 0);
15411542
annotation_robot_t annotation_robot = ANNOTATION_ROBOT_NONE;
@@ -1546,6 +1547,8 @@ int parsemail(char *mbox, /* file name */
15461547
int require_filter_len, require_filter_full_len;
15471548
struct hmlist *tlist;
15481549
char filename[MAXFILELEN];
1550+
char directory[MAXFILELEN];
1551+
char pathname[MAXFILELEN];
15491552
struct emailinfo *emp;
15501553
char *att_dir = NULL; /* directory name to store attachments in */
15511554
char *meta_dir = NULL; /* directory name where we're storing the meta data
@@ -1660,21 +1663,31 @@ int parsemail(char *mbox, /* file name */
16601663
if(set_append) {
16611664

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

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)