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.
12 static struct swit switches[] = {
21 main(int argc, char **argv)
24 char *cp, *maildir, *folder = NULL;
26 char **arguments, buf[BUFSIZ];
27 struct msgs_array msgs = { 0, 0, NULL };
31 setlocale(LC_ALL, "");
33 invo_name = mhbasename(argv[0]);
35 /* read user profile/context */
38 arguments = getarguments(invo_name, argc, argv, 1);
44 while ((cp = *argp++)) {
46 switch (smatch(++cp, switches)) {
48 ambigsw(cp, switches);
51 adios(NULL, "-%s unknown", cp);
54 snprintf(buf, sizeof(buf), "%s [+folder] [msgs] [switches]", invo_name);
55 print_help(buf, switches, 1);
58 print_version(invo_name);
62 if (*cp == '+' || *cp == '@') {
64 adios(NULL, "only one folder at a time!");
66 folder = getcpy(expandfol(cp));
68 app_msgarg(&msgs, cp);
73 maildir = toabsdir(folder);
75 /* If no messages are given, print folder pathname */
77 printf("%s\n", maildir);
81 if (chdir(maildir) == NOTOK)
82 adios(maildir, "unable to change directory to");
84 /* read folder and create message structure */
85 if (!(mp = folder_read(folder)))
86 adios(NULL, "unable to read folder %s", folder);
89 ** We need to make sure there is message status space
90 ** for all the message numbers from 1 to "new" since
91 ** mhpath can select empty slots. If we are adding
92 ** space at the end, we go ahead and add 10 slots.
94 if (mp->hghmsg >= mp->hghoff) {
95 if (!(mp = folder_realloc(mp, 1, mp->hghmsg + 10)))
96 adios(NULL, "unable to allocate folder storage");
97 } else if (mp->lowoff > 1) {
98 if (!(mp = folder_realloc(mp, 1, mp->hghoff)))
99 adios(NULL, "unable to allocate folder storage");
102 mp->msgflags |= ALLOW_NEW; /* allow the "new" sequence */
104 /* parse all the message ranges/sequences and set SELECTED */
105 for (i = 0; i < msgs.size; i++)
106 if (!m_convert(mp, msgs.msgs[i]))
109 seq_setprev(mp); /* set the previous-sequence */
111 /* print the path of all selected messages */
112 for (i = mp->lowsel; i <= mp->hghsel; i++)
113 if (is_selected(mp, i))
114 printf("%s/%s\n", mp->foldpath, m_name(i));
116 seq_save(mp); /* synchronize message sequences */
117 context_save(); /* save the context file */
118 folder_free(mp); /* free folder/message structure */