Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mdirs: add Maildir profile key #245

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ SCRIPT = mcolor mcom mless mmkdir mquote museragent
all: $(ALL) museragent

$(ALL) : % : %.o
maddr magrep mdeliver mexport mflag mflow mgenmid mhdr mpick mscan msed mshow \
msort mthread : blaze822.o mymemmem.o mytimegm.o
maddr magrep mdeliver mexport mflag mgenmid mhdr minc mlist mpick mscan msed \
mseq mshow msort mthread : seq.o slurp.o mystrverscmp.o
maddr magrep mdeliver mdirs mexport mflag mflow mgenmid mhdr mpick mscan msed \
mshow msort mthread : blaze822.o mymemmem.o mytimegm.o
maddr magrep mdeliver mdirs mexport mflag mgenmid mhdr minc mlist mpick mscan \
msed mseq mshow msort mthread : seq.o slurp.o mystrverscmp.o
maddr magrep mflow mhdr mpick mscan mshow : rfc2047.o
magrep mflow mhdr mshow : rfc2045.o
mshow : filter.o safe_u8putstr.o rfc2231.o pipeto.o
Expand Down
4 changes: 4 additions & 0 deletions man/mblaze-profile.5
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ The fully qualified domain name used for
.Li Message\&-Id\&:
generation in
.Xr mgenmid 1 .
.It Li Maildir\&:
If set,
.Xr mdirs 1
will use this maildir when no directories are supplied.
.It Li Outbox\&:
If set,
.Xr mcom 1
Expand Down
22 changes: 20 additions & 2 deletions man/mdirs.1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.Dd January 22, 2020
.Dd July 25, 2023
.Dt MDIRS 1
.Os
.Sh NAME
Expand All @@ -17,6 +17,14 @@ for maildir
folders and prints them,
separated by newlines.
.Pp
If
.Ar dirs
is not present then use
.Sq Li Maildir\&:
from
.Pa "${MBLAZE:-$HOME/.mblaze}/profile"
.Pq if set .
.Pp
To
.Nm ,
a maildir folder is a directory containing
Expand All @@ -36,10 +44,20 @@ Print folders separated by a NUL character.
.It Fl a
Traverse into all subfolders, without considering the maildir++ name conventions.
.El
.Sh ENVIRONMENT
.Bl -tag -width Ds
.It Ev MBLAZE
Directory containing mblaze configuration.
.Po
Default:
.Pa $HOME/.mblaze
.Pc
.El
.Sh EXIT STATUS
.Ex -std
.Sh SEE ALSO
.Xr find 1
.Xr find 1 ,
.Xr mblaze-profile 5
.Sh AUTHORS
.An Leah Neukirchen Aq Mt leah@vuxu.org
.Sh LICENSE
Expand Down
41 changes: 38 additions & 3 deletions mdirs.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@

#include <dirent.h>
#include <limits.h>
#include <pwd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

#include "blaze822.h"
Expand Down Expand Up @@ -72,6 +74,33 @@ mdirs(char *fpath)
closedir(dir);
}

char *
profile_maildir()
{
char *f = blaze822_home_file("profile");
struct message *config = blaze822(f);
char *maildir;
static char path[PATH_MAX];

if (!config)
return 0;

if (!(maildir = blaze822_hdr(config, "maildir")))
return 0;

if (strncmp(maildir, "~/", 2) == 0) {
const char *home = getenv("HOME");
if (!home) {
struct passwd *pw = getpwuid(getuid());
home = pw ? pw->pw_dir : "/dev/null/homeless";
}
snprintf(path, sizeof path, "%s/%s", home, maildir+2);
maildir = path;
}

return maildir;
}

int
main(int argc, char *argv[])
{
Expand All @@ -86,11 +115,17 @@ main(int argc, char *argv[])
exit(1);
}

if (argc == optind)
goto usage;

xpledge("stdio rpath", "");

if (argc == optind) {
char *maildir = profile_maildir();
if (maildir) {
mdirs(maildir);
return 0;
}
goto usage;
}

char toplevel[PATH_MAX];
if (!getcwd(toplevel, sizeof toplevel)) {
perror("mdirs: getcwd");
Expand Down