]>
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/folder_read.h"
10 #include "sbr/folder_realloc.h"
11 #include "sbr/folder_free.h"
12 #include "sbr/context_save.h"
13 #include "sbr/context_find.h"
14 #include "sbr/ambigsw.h"
16 #include "sbr/print_version.h"
17 #include "sbr/print_help.h"
18 #include "sbr/error.h"
21 #include "sbr/m_maildir.h"
23 #define MHPATH_SWITCHES \
24 X("version", 0, VERSIONSW) \
25 X("help", 0, HELPSW) \
27 #define X(sw, minchars, id) id,
28 DEFINE_SWITCH_ENUM(MHPATH
);
31 #define X(sw, minchars, id) { sw, minchars, id },
32 DEFINE_SWITCH_ARRAY(MHPATH
, switches
);
36 main(int argc
, char **argv
)
39 char *cp
, *maildir
, *folder
= NULL
;
41 char **arguments
, buf
[BUFSIZ
];
42 struct msgs_array msgs
= { 0, 0, NULL
};
45 if (nmh_init(argv
[0], true, false)) { return 1; }
47 arguments
= getarguments (invo_name
, argc
, argv
, 1);
53 while ((cp
= *argp
++)) {
55 switch (smatch (++cp
, switches
)) {
57 ambigsw (cp
, switches
);
60 die("-%s unknown", cp
);
63 snprintf (buf
, sizeof(buf
), "%s [+folder] [msgs] [switches]",
65 print_help (buf
, switches
, 1);
68 print_version(invo_name
);
72 if (*cp
== '+' || *cp
== '@') {
74 die("only one folder at a time!");
75 folder
= pluspath (cp
);
77 app_msgarg(&msgs
, cp
);
80 if (!context_find ("path"))
81 free (path ("./", TFOLDER
));
84 folder
= getfolder (1);
85 maildir
= m_maildir (folder
);
87 /* If no messages are given, print folder pathname */
93 if (chdir (maildir
) == NOTOK
)
94 adios (maildir
, "unable to change directory to");
96 /* read folder and create message structure */
97 if (!(mp
= folder_read (folder
, 1)))
98 die("unable to read folder %s", folder
);
101 * We need to make sure there is message status space
102 * for all the message numbers from 1 to "new" since
103 * mhpath can select empty slots. If we are adding
104 * space at the end, we go ahead and add 10 slots.
106 if (mp
->hghmsg
>= mp
->hghoff
) {
107 if (!(mp
= folder_realloc (mp
, 1, mp
->hghmsg
+ 10)))
108 die("unable to allocate folder storage");
109 } else if (mp
->lowoff
> 1) {
110 if (!(mp
= folder_realloc (mp
, 1, mp
->hghoff
)))
111 die("unable to allocate folder storage");
114 mp
->msgflags
|= ALLOW_NEW
; /* allow the "new" sequence */
116 /* parse all the message ranges/sequences and set SELECTED */
117 for (i
= 0; i
< msgs
.size
; i
++)
118 if (!m_convert (mp
, msgs
.msgs
[i
]))
121 seq_setprev (mp
); /* set the previous-sequence */
123 /* print the path of all selected messages */
124 for (i
= mp
->lowsel
; i
<= mp
->hghsel
; i
++)
125 if (is_selected (mp
, i
))
126 printf ("%s/%s\n", mp
->foldpath
, m_name (i
));
128 seq_save (mp
); /* synchronize message sequences */
129 context_save (); /* save the context file */
130 folder_free (mp
); /* free folder/message structure */