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 };
30 setlocale(LC_ALL, "");
31 invo_name = mhbasename(argv[0]);
33 /* read user profile/context */
36 arguments = getarguments(invo_name, argc, argv, 1);
42 while ((cp = *argp++)) {
44 switch (smatch(++cp, switches)) {
46 ambigsw(cp, switches);
49 adios(NULL, "-%s unknown", cp);
52 snprintf(buf, sizeof(buf), "%s [+folder] [msgs] [switches]", invo_name);
53 print_help(buf, switches, 1);
56 print_version(invo_name);
60 if (*cp == '+' || *cp == '@') {
62 adios(NULL, "only one folder at a time!");
64 folder = getcpy(expandfol(cp));
66 app_msgarg(&msgs, cp);
71 maildir = toabsdir(folder);
73 /* If no messages are given, print folder pathname */
75 printf("%s\n", maildir);
79 if (chdir(maildir) == NOTOK)
80 adios(maildir, "unable to change directory to");
82 /* read folder and create message structure */
83 if (!(mp = folder_read(folder)))
84 adios(NULL, "unable to read folder %s", folder);
87 ** We need to make sure there is message status space
88 ** for all the message numbers from 1 to one beyond last since
89 ** mhpath can select empty slots. If we are adding
90 ** space at the end, we go ahead and add 10 slots.
92 if (mp->hghmsg >= mp->hghoff) {
93 if (!(mp = folder_realloc(mp, 1, mp->hghmsg + 10)))
94 adios(NULL, "unable to allocate folder storage");
95 } else if (mp->lowoff > 1) {
96 if (!(mp = folder_realloc(mp, 1, mp->hghoff)))
97 adios(NULL, "unable to allocate folder storage");
100 ** TODO: As folder_realloc() checks itself if the realloc
101 ** really is necesary, why don't we then:
102 ** if (!(mp = folder_realloc (mp, 1, mp->hghmsg+1)))
103 ** adios (NULL, "unable to allocate folder storage");
104 ** ? This at least appears most clear to me. -- meillo
108 mp->msgflags |= ALLOW_BEYOND; /* allow the beyond sequence */
110 /* parse all the message ranges/sequences and set SELECTED */
111 for (i = 0; i < msgs.size; i++)
112 if (!m_convert(mp, msgs.msgs[i]))
115 seq_setprev(mp); /* set the previous-sequence */
117 /* print the path of all selected messages */
118 for (i = mp->lowsel; i <= mp->hghsel; i++)
119 if (is_selected(mp, i))
120 printf("%s/%s\n", mp->foldpath, m_name(i));
122 seq_save(mp); /* synchronize message sequences */
123 context_save(); /* save the context file */
124 folder_free(mp); /* free folder/message structure */