2 ** mhpath.c -- print full pathnames of nmh messages and folders
4 ** This code is Copyright (c) 2002, by the authors of nmh. See the
5 ** COPYRIGHT file in the root directory of the nmh distribution for
6 ** complete copyright information.
15 static struct swit switches[] = {
24 main(int argc, char **argv)
27 char *cp, *maildir, *folder = NULL;
29 char **arguments, buf[BUFSIZ];
30 struct msgs_array msgs = { 0, 0, NULL };
33 setlocale(LC_ALL, "");
34 invo_name = mhbasename(argv[0]);
36 /* read user profile/context */
39 arguments = getarguments(invo_name, argc, argv, 1);
45 while ((cp = *argp++)) {
47 switch (smatch(++cp, switches)) {
49 ambigsw(cp, switches);
52 adios(EX_USAGE, NULL, "-%s unknown", cp);
55 snprintf(buf, sizeof(buf), "%s [+folder] [msgs] [switches]", invo_name);
56 print_help(buf, switches, 1);
57 exit(argc == 2 ? EX_OK : EX_USAGE);
59 print_version(invo_name);
60 exit(argc == 2 ? EX_OK : EX_USAGE);
63 if (*cp == '+' || *cp == '@') {
65 adios(EX_USAGE, NULL, "only one folder at a time!");
67 folder = getcpy(expandfol(cp));
70 app_msgarg(&msgs, cp);
76 maildir = toabsdir(folder);
78 /* If no messages are given, print folder pathname */
80 printf("%s\n", maildir);
84 if (chdir(maildir) == NOTOK)
85 adios(EX_OSERR, maildir, "unable to change directory to");
87 /* read folder and create message structure */
88 if (!(mp = folder_read(folder)))
89 adios(EX_IOERR, NULL, "unable to read folder %s", folder);
92 ** We need to make sure there is message status space
93 ** for all the message numbers from 1 to one beyond last since
94 ** mhpath can select empty slots. If we are adding
95 ** space at the end, we go ahead and add 10 slots.
97 if (mp->hghmsg >= mp->hghoff) {
98 if (!(mp = folder_realloc(mp, 1, mp->hghmsg + 10))) {
99 adios(EX_OSERR, NULL, "unable to allocate folder storage");
101 } else if (mp->lowoff > 1) {
102 if (!(mp = folder_realloc(mp, 1, mp->hghoff))) {
103 adios(EX_OSERR, NULL, "unable to allocate folder storage");
107 ** TODO: As folder_realloc() checks itself if the realloc
108 ** really is necesary, why don't we then:
109 ** if (!(mp = folder_realloc (mp, 1, mp->hghmsg+1)))
110 ** adios (NULL, "unable to allocate folder storage");
111 ** ? This at least appears most clear to me. -- meillo
115 mp->msgflags |= ALLOW_BEYOND; /* allow the beyond sequence */
117 /* parse all the message ranges/sequences and set SELECTED */
118 for (i = 0; i < msgs.size; i++) {
119 if (!m_convert(mp, msgs.msgs[i])) {
124 seq_setprev(mp); /* set the previous-sequence */
126 /* print the path of all selected messages */
127 for (i = mp->lowsel; i <= mp->hghsel; i++)
128 if (is_selected(mp, i))
129 printf("%s/%s\n", mp->foldpath, m_name(i));
131 seq_save(mp); /* synchronize message sequences */
132 context_save(); /* save the context file */
133 folder_free(mp); /* free folder/message structure */