]>
diplodocus.org Git - nmh/blob - uip/mhpath.c
4f6a7c3f2313103d030e45aee9737da64a7902a7
1 /* mhpath.c -- print full pathnames of nmh messages and folders
3 * This code is Copyright (c) 2002, by the authors of nmh. See the
4 * COPYRIGHT file in the root directory of the nmh distribution for
5 * complete copyright information.
9 #include "sbr/ambigsw.h"
11 #include "sbr/print_version.h"
12 #include "sbr/print_help.h"
13 #include "sbr/error.h"
16 #include "sbr/m_maildir.h"
18 #define MHPATH_SWITCHES \
19 X("version", 0, VERSIONSW) \
20 X("help", 0, HELPSW) \
22 #define X(sw, minchars, id) id,
23 DEFINE_SWITCH_ENUM(MHPATH
);
26 #define X(sw, minchars, id) { sw, minchars, id },
27 DEFINE_SWITCH_ARRAY(MHPATH
, switches
);
31 main(int argc
, char **argv
)
34 char *cp
, *maildir
, *folder
= NULL
;
36 char **arguments
, buf
[BUFSIZ
];
37 struct msgs_array msgs
= { 0, 0, NULL
};
40 if (nmh_init(argv
[0], true, false)) { return 1; }
42 arguments
= getarguments (invo_name
, argc
, argv
, 1);
48 while ((cp
= *argp
++)) {
50 switch (smatch (++cp
, switches
)) {
52 ambigsw (cp
, switches
);
55 die("-%s unknown", cp
);
58 snprintf (buf
, sizeof(buf
), "%s [+folder] [msgs] [switches]",
60 print_help (buf
, switches
, 1);
63 print_version(invo_name
);
67 if (*cp
== '+' || *cp
== '@') {
69 die("only one folder at a time!");
70 folder
= pluspath (cp
);
72 app_msgarg(&msgs
, cp
);
75 if (!context_find ("path"))
76 free (path ("./", TFOLDER
));
79 folder
= getfolder (1);
80 maildir
= m_maildir (folder
);
82 /* If no messages are given, print folder pathname */
88 if (chdir (maildir
) == NOTOK
)
89 adios (maildir
, "unable to change directory to");
91 /* read folder and create message structure */
92 if (!(mp
= folder_read (folder
, 1)))
93 die("unable to read folder %s", folder
);
96 * We need to make sure there is message status space
97 * for all the message numbers from 1 to "new" since
98 * mhpath can select empty slots. If we are adding
99 * space at the end, we go ahead and add 10 slots.
101 if (mp
->hghmsg
>= mp
->hghoff
) {
102 if (!(mp
= folder_realloc (mp
, 1, mp
->hghmsg
+ 10)))
103 die("unable to allocate folder storage");
104 } else if (mp
->lowoff
> 1) {
105 if (!(mp
= folder_realloc (mp
, 1, mp
->hghoff
)))
106 die("unable to allocate folder storage");
109 mp
->msgflags
|= ALLOW_NEW
; /* allow the "new" sequence */
111 /* parse all the message ranges/sequences and set SELECTED */
112 for (i
= 0; i
< msgs
.size
; i
++)
113 if (!m_convert (mp
, msgs
.msgs
[i
]))
116 seq_setprev (mp
); /* set the previous-sequence */
118 /* print the path of all selected messages */
119 for (i
= mp
->lowsel
; i
<= mp
->hghsel
; i
++)
120 if (is_selected (mp
, i
))
121 printf ("%s/%s\n", mp
->foldpath
, m_name (i
));
123 seq_save (mp
); /* synchronize message sequences */
124 context_save (); /* save the context file */
125 folder_free (mp
); /* free folder/message structure */