]>
diplodocus.org Git - nmh/blob - uip/mhpath.c
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/m_convert.h"
10 #include "sbr/getfolder.h"
11 #include "sbr/folder_read.h"
12 #include "sbr/folder_realloc.h"
13 #include "sbr/folder_free.h"
14 #include "sbr/context_save.h"
15 #include "sbr/context_find.h"
16 #include "sbr/ambigsw.h"
18 #include "sbr/print_version.h"
19 #include "sbr/print_help.h"
20 #include "sbr/error.h"
23 #include "sbr/m_maildir.h"
25 #define MHPATH_SWITCHES \
26 X("version", 0, VERSIONSW) \
27 X("help", 0, HELPSW) \
29 #define X(sw, minchars, id) id,
30 DEFINE_SWITCH_ENUM(MHPATH
);
33 #define X(sw, minchars, id) { sw, minchars, id },
34 DEFINE_SWITCH_ARRAY(MHPATH
, switches
);
38 main(int argc
, char **argv
)
41 char *cp
, *maildir
, *folder
= NULL
;
43 char **arguments
, buf
[BUFSIZ
];
44 struct msgs_array msgs
= { 0, 0, NULL
};
47 if (nmh_init(argv
[0], true, false)) { return 1; }
49 arguments
= getarguments (invo_name
, argc
, argv
, 1);
55 while ((cp
= *argp
++)) {
57 switch (smatch (++cp
, switches
)) {
59 ambigsw (cp
, switches
);
62 die("-%s unknown", cp
);
65 snprintf (buf
, sizeof(buf
), "%s [+folder] [msgs] [switches]",
67 print_help (buf
, switches
, 1);
70 print_version(invo_name
);
74 if (*cp
== '+' || *cp
== '@') {
76 die("only one folder at a time!");
77 folder
= pluspath (cp
);
79 app_msgarg(&msgs
, cp
);
82 if (!context_find ("path"))
83 free (path ("./", TFOLDER
));
86 folder
= getfolder (1);
87 maildir
= m_maildir (folder
);
89 /* If no messages are given, print folder pathname */
95 if (chdir (maildir
) == NOTOK
)
96 adios (maildir
, "unable to change directory to");
98 /* read folder and create message structure */
99 if (!(mp
= folder_read (folder
, 1)))
100 die("unable to read folder %s", folder
);
103 * We need to make sure there is message status space
104 * for all the message numbers from 1 to "new" since
105 * mhpath can select empty slots. If we are adding
106 * space at the end, we go ahead and add 10 slots.
108 if (mp
->hghmsg
>= mp
->hghoff
) {
109 if (!(mp
= folder_realloc (mp
, 1, mp
->hghmsg
+ 10)))
110 die("unable to allocate folder storage");
111 } else if (mp
->lowoff
> 1) {
112 if (!(mp
= folder_realloc (mp
, 1, mp
->hghoff
)))
113 die("unable to allocate folder storage");
116 mp
->msgflags
|= ALLOW_NEW
; /* allow the "new" sequence */
118 /* parse all the message ranges/sequences and set SELECTED */
119 for (i
= 0; i
< msgs
.size
; i
++)
120 if (!m_convert (mp
, msgs
.msgs
[i
]))
123 seq_setprev (mp
); /* set the previous-sequence */
125 /* print the path of all selected messages */
126 for (i
= mp
->lowsel
; i
<= mp
->hghsel
; i
++)
127 if (is_selected (mp
, i
))
128 printf ("%s/%s\n", mp
->foldpath
, m_name (i
));
130 seq_save (mp
); /* synchronize message sequences */
131 context_save (); /* save the context file */
132 folder_free (mp
); /* free folder/message structure */