Skip to content

Commit

Permalink
Maildir: support winnt/ntfs based systems (currently midipix).
Browse files Browse the repository at this point in the history
Per the Maildir specification, the info (trailing) part of message
filenames is identified by a <colon><spec_version><comma>; however,
on WINNT/NTFS, a colon may not be part of a filename, therefore use
a <semicolon> instead. Since the default remains to use a <colon>,
all targets (other than those definining the __winnt__ macro)
should remain unaffected by this change.
  • Loading branch information
midipix authored and leahneukirchen committed Jun 15, 2024
1 parent d5e202b commit b078f8c
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 20 deletions.
11 changes: 11 additions & 0 deletions blaze822.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@
#define PATH_MAX 4096
#endif

// maildir filename suffix: use a semicolon on winnt/ntfs, otherwise a colon
#ifdef __winnt__
#define MAILDIR_COLON ';'
#define MAILDIR_COLON_SPEC_VER ";2"
#define MAILDIR_COLON_SPEC_VER_COMMA ";2,"
#else
#define MAILDIR_COLON ':'
#define MAILDIR_COLON_SPEC_VER ":2"
#define MAILDIR_COLON_SPEC_VER_COMMA ":2,"
#endif

struct message;

// blaze822.c
Expand Down
2 changes: 1 addition & 1 deletion magrep.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ void
magrep(char *file)
{
if (!*header) {
char *flags = strstr(file, ":2,");
char *flags = strstr(file, MAILDIR_COLON_SPEC_VER_COMMA);
if (flags)
match(file, "flags", flags+3);
return;
Expand Down
8 changes: 4 additions & 4 deletions mdeliver.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ deliver(char *infilename)
snprintf(tmp, sizeof tmp, "%s/tmp/%s", targetdir, id);

if (try_rename) {
snprintf(dst, sizeof dst, "%s/%s/%s:2,%s",
snprintf(dst, sizeof dst, "%s/%s/%s"MAILDIR_COLON_SPEC_VER_COMMA"%s",
targetdir, cflag ? "cur" : "new", id, Xflag);
if (rename(infilename, dst) == 0)
goto success;
Expand Down Expand Up @@ -173,7 +173,7 @@ deliver(char *infilename)
if (Mflag && in_header &&
(strncasecmp("status:", line, 7) == 0 ||
strncasecmp("x-status:", line, 9) == 0)) {
char *v = strchr(line, ':');
char *v = strchr(line, MAILDIR_COLON);
if (v) {
if (strchr(v, 'F')) statusflags[0] = 'F';
if (strchr(v, 'A')) statusflags[1] = 'R';
Expand Down Expand Up @@ -257,7 +257,7 @@ deliver(char *infilename)
#endif
}

snprintf(dst, sizeof dst, "%s/%s/%s:2,%s",
snprintf(dst, sizeof dst, "%s/%s/%s"MAILDIR_COLON_SPEC_VER_COMMA"%s",
targetdir, (cflag || is_old) ? "cur" : "new", id,
Xflag ? Xflag : statusflags);
if (rename(tmp, dst) != 0)
Expand Down Expand Up @@ -285,7 +285,7 @@ refile(char *file)
file++;

// keep flags
char *flags = strstr(file, ":2,");
char *flags = strstr(file, MAILDIR_COLON_SPEC_VER_COMMA);
if (flags)
Xflag = flags + 3;
else
Expand Down
2 changes: 1 addition & 1 deletion mexport.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export(char *file)

if (in_header && line[0] == '\n' && !line[1]) {
if (Sflag) {
char *flags = strstr(file, ":2,");
char *flags = strstr(file, MAILDIR_COLON_SPEC_VER_COMMA);
if (!flags)
flags = "";

Expand Down
2 changes: 1 addition & 1 deletion mflag.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ flag(char *file)
while (file[indent] == ' ' || file[indent] == '\t')
indent++;

char *f = strstr(file, ":2,");
char *f = strstr(file, MAILDIR_COLON_SPEC_VER_COMMA);
if (!f)
goto skip;

Expand Down
3 changes: 2 additions & 1 deletion minc.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ inc(char *dir)
snprintf(src, sizeof src, "%s/new/%s",
dir, d->d_name);
snprintf(dst, sizeof dst, "%s/cur/%s%s",
dir, d->d_name, strstr(d->d_name, ":2,") ? "" : ":2,");
dir, d->d_name,
strstr(d->d_name, MAILDIR_COLON_SPEC_VER_COMMA) ? "" : MAILDIR_COLON_SPEC_VER_COMMA);
if (rename(src, dst) < 0) {
fprintf(stderr, "minc: can't rename '%s' to '%s': %s\n",
src, dst, strerror(errno));
Expand Down
4 changes: 2 additions & 2 deletions mlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,14 @@ list(char *prefix, char *file)
if (flagset || iflag) {
size_t prefixlen;

f = strstr(file, ":2,");
f = strstr(file, MAILDIR_COLON_SPEC_VER_COMMA);

if (!f &&
prefix &&
(prefixlen = strlen(prefix)) &&
prefixlen >= 4 &&
strcmp(prefix + prefixlen - 4, "/new") == 0)
f = ":2,";
f = MAILDIR_COLON_SPEC_VER_COMMA;
}

if (flagset) {
Expand Down
2 changes: 1 addition & 1 deletion mpick.c
Original file line number Diff line number Diff line change
Expand Up @@ -1290,7 +1290,7 @@ mailfile(struct mailinfo *m, char *file)
cur_idx = m->index;
}

char *f = strstr(fpath, ":2,");
char *f = strstr(fpath, MAILDIR_COLON_SPEC_VER_COMMA);
if (f) {
if (strchr(f, 'P'))
m->flags |= FLAG_PASSED;
Expand Down
2 changes: 1 addition & 1 deletion mscan.c
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ oneline(char *file)
}

struct message *msg = blaze822(file);
char *flags = msg ? strstr(file, ":2,") : 0;
char *flags = msg ? strstr(file, MAILDIR_COLON_SPEC_VER_COMMA) : 0;
if (!flags)
flags = "";
else
Expand Down
8 changes: 4 additions & 4 deletions mseq.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ namescan(char *dir)
snprintf(file, sizeof file, "%s/%s", dir, d->d_name);

char *e;
if ((e = strstr(d->d_name, ":2,")))
if ((e = strstr(d->d_name, MAILDIR_COLON_SPEC_VER_COMMA)))
*e = 0;

struct name *c = malloc(sizeof (struct name));
Expand Down Expand Up @@ -101,7 +101,7 @@ search(char *file)
if (!namefind(dir))
namescan(dir);

if ((e = strstr(file, ":2,")))
if ((e = strstr(file, MAILDIR_COLON_SPEC_VER_COMMA)))
*e = 0;

return namefind(file);
Expand Down Expand Up @@ -131,11 +131,11 @@ fix(FILE *out, char *file)
char *e;
char *sep;

if ((e = strstr(file, ":2,"))) {
if ((e = strstr(file, MAILDIR_COLON_SPEC_VER_COMMA))) {
sep = "";
e[3] = 0;
} else {
sep = ":2,";
sep = MAILDIR_COLON_SPEC_VER_COMMA;
}
snprintf(buf, sizeof buf, "%s%s", file, sep);
if (access(buf, F_OK) == 0) goto ok;
Expand Down
8 changes: 4 additions & 4 deletions msort.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,8 @@ unreadorder(const void *a, const void *b)
struct mail *ia = (struct mail *)a;
struct mail *ib = (struct mail *)b;

char *fa = strstr(ia->file, ":2,");
char *fb = strstr(ib->file, ":2,");
char *fa = strstr(ia->file, MAILDIR_COLON_SPEC_VER_COMMA);
char *fb = strstr(ib->file, MAILDIR_COLON_SPEC_VER_COMMA);

int unreada = fa ? !strchr(fa, 'S') : 0;
int unreadb = fb ? !strchr(fb, 'S') : 0;
Expand All @@ -234,8 +234,8 @@ flaggedorder(const void *a, const void *b)
struct mail *ia = (struct mail *)a;
struct mail *ib = (struct mail *)b;

char *fa = strstr(ia->file, ":2,");
char *fb = strstr(ib->file, ":2,");
char *fa = strstr(ia->file, MAILDIR_COLON_SPEC_VER_COMMA);
char *fb = strstr(ib->file, MAILDIR_COLON_SPEC_VER_COMMA);

int unreada = fa ? !!strchr(fa, 'F') : 0;
int unreadb = fb ? !!strchr(fb, 'F') : 0;
Expand Down

0 comments on commit b078f8c

Please sign in to comment.