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[] = {
23 char *version=VERSION;
26 main(int argc, char **argv)
29 char *cp, *maildir, *folder = NULL;
31 char **arguments, buf[BUFSIZ];
32 struct msgs_array msgs = { 0, 0, NULL };
35 setlocale(LC_ALL, "");
36 invo_name = mhbasename(argv[0]);
38 /* read user profile/context */
41 arguments = getarguments(invo_name, argc, argv, 1);
47 while ((cp = *argp++)) {
49 switch (smatch(++cp, switches)) {
51 ambigsw(cp, switches);
54 adios(EX_USAGE, NULL, "-%s unknown", cp);
57 snprintf(buf, sizeof(buf), "%s [+folder] [msgs] [switches]", invo_name);
58 print_help(buf, switches, 1);
59 exit(argc == 2 ? EX_OK : EX_USAGE);
61 print_version(invo_name);
62 exit(argc == 2 ? EX_OK : EX_USAGE);
65 if (*cp == '+' || *cp == '@') {
67 adios(EX_USAGE, NULL, "only one folder at a time!");
69 folder = mh_xstrdup(expandfol(cp));
72 app_msgarg(&msgs, cp);
78 maildir = toabsdir(folder);
80 /* If no messages are given, print folder pathname */
82 printf("%s\n", maildir);
86 if (chdir(maildir) == NOTOK)
87 adios(EX_OSERR, maildir, "unable to change directory to");
89 /* read folder and create message structure */
90 if (!(mp = folder_read(folder)))
91 adios(EX_IOERR, NULL, "unable to read folder %s", folder);
94 ** We need to make sure there is message status space
95 ** for all the message numbers from 1 to one beyond last since
96 ** mhpath can select empty slots. If we are adding
97 ** space at the end, we go ahead and add 10 slots.
99 if (mp->hghmsg >= mp->hghoff) {
100 if (!(mp = folder_realloc(mp, 1, mp->hghmsg + 10))) {
101 adios(EX_OSERR, NULL, "unable to allocate folder storage");
103 } else if (mp->lowoff > 1) {
104 if (!(mp = folder_realloc(mp, 1, mp->hghoff))) {
105 adios(EX_OSERR, NULL, "unable to allocate folder storage");
109 ** TODO: As folder_realloc() checks itself if the realloc
110 ** really is necessary, why don't we then:
111 ** if (!(mp = folder_realloc (mp, 1, mp->hghmsg+1)))
112 ** adios (NULL, "unable to allocate folder storage");
113 ** ? This at least appears most clear to me. -- meillo
117 mp->msgflags |= ALLOW_BEYOND; /* allow the beyond sequence */
119 /* parse all the message ranges/sequences and set SELECTED */
120 for (i = 0; i < msgs.size; i++) {
121 if (!m_convert(mp, msgs.msgs[i])) {
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 */