]>
diplodocus.org Git - nmh/blob - uip/mhpath.c
ecb805525df7981ee9f8d2a10eb5b30f277738eb
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/context_find.h"
10 #include "sbr/ambigsw.h"
12 #include "sbr/print_version.h"
13 #include "sbr/print_help.h"
14 #include "sbr/error.h"
17 #include "sbr/m_maildir.h"
19 #define MHPATH_SWITCHES \
20 X("version", 0, VERSIONSW) \
21 X("help", 0, HELPSW) \
23 #define X(sw, minchars, id) id,
24 DEFINE_SWITCH_ENUM(MHPATH
);
27 #define X(sw, minchars, id) { sw, minchars, id },
28 DEFINE_SWITCH_ARRAY(MHPATH
, switches
);
32 main(int argc
, char **argv
)
35 char *cp
, *maildir
, *folder
= NULL
;
37 char **arguments
, buf
[BUFSIZ
];
38 struct msgs_array msgs
= { 0, 0, NULL
};
41 if (nmh_init(argv
[0], true, false)) { return 1; }
43 arguments
= getarguments (invo_name
, argc
, argv
, 1);
49 while ((cp
= *argp
++)) {
51 switch (smatch (++cp
, switches
)) {
53 ambigsw (cp
, switches
);
56 die("-%s unknown", cp
);
59 snprintf (buf
, sizeof(buf
), "%s [+folder] [msgs] [switches]",
61 print_help (buf
, switches
, 1);
64 print_version(invo_name
);
68 if (*cp
== '+' || *cp
== '@') {
70 die("only one folder at a time!");
71 folder
= pluspath (cp
);
73 app_msgarg(&msgs
, cp
);
76 if (!context_find ("path"))
77 free (path ("./", TFOLDER
));
80 folder
= getfolder (1);
81 maildir
= m_maildir (folder
);
83 /* If no messages are given, print folder pathname */
89 if (chdir (maildir
) == NOTOK
)
90 adios (maildir
, "unable to change directory to");
92 /* read folder and create message structure */
93 if (!(mp
= folder_read (folder
, 1)))
94 die("unable to read folder %s", folder
);
97 * We need to make sure there is message status space
98 * for all the message numbers from 1 to "new" since
99 * mhpath can select empty slots. If we are adding
100 * space at the end, we go ahead and add 10 slots.
102 if (mp
->hghmsg
>= mp
->hghoff
) {
103 if (!(mp
= folder_realloc (mp
, 1, mp
->hghmsg
+ 10)))
104 die("unable to allocate folder storage");
105 } else if (mp
->lowoff
> 1) {
106 if (!(mp
= folder_realloc (mp
, 1, mp
->hghoff
)))
107 die("unable to allocate folder storage");
110 mp
->msgflags
|= ALLOW_NEW
; /* allow the "new" sequence */
112 /* parse all the message ranges/sequences and set SELECTED */
113 for (i
= 0; i
< msgs
.size
; i
++)
114 if (!m_convert (mp
, msgs
.msgs
[i
]))
117 seq_setprev (mp
); /* set the previous-sequence */
119 /* print the path of all selected messages */
120 for (i
= mp
->lowsel
; i
<= mp
->hghsel
; i
++)
121 if (is_selected (mp
, i
))
122 printf ("%s/%s\n", mp
->foldpath
, m_name (i
));
124 seq_save (mp
); /* synchronize message sequences */
125 context_save (); /* save the context file */
126 folder_free (mp
); /* free folder/message structure */