]>
diplodocus.org Git - nmh/blob - uip/mhpath.c
3 * mhpath.c -- print full pathnames of nmh messages and folders
5 * This code is Copyright (c) 2002, by the authors of nmh. See the
6 * COPYRIGHT file in the root directory of the nmh distribution for
7 * complete copyright information.
13 #define MHPATH_SWITCHES \
14 X("version", 0, VERSIONSW) \
15 X("help", 0, HELPSW) \
17 #define X(sw, minchars, id) id,
18 DEFINE_SWITCH_ENUM(MHPATH
);
21 #define X(sw, minchars, id) { sw, minchars, id },
22 DEFINE_SWITCH_ARRAY(MHPATH
, switches
);
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
};
36 setlocale(LC_ALL
, "");
38 invo_name
= r1bindex (argv
[0], '/');
40 /* read user profile/context */
43 arguments
= getarguments (invo_name
, argc
, argv
, 1);
49 while ((cp
= *argp
++)) {
51 switch (smatch (++cp
, switches
)) {
53 ambigsw (cp
, switches
);
56 adios (NULL
, "-%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 adios (NULL
, "only one folder at a time!");
72 folder
= pluspath (cp
);
74 app_msgarg(&msgs
, cp
);
77 if (!context_find ("path"))
78 free (path ("./", TFOLDER
));
81 folder
= getfolder (1);
82 maildir
= m_maildir (folder
);
84 /* If no messages are given, print folder pathname */
86 printf ("%s\n", maildir
);
90 if (chdir (maildir
) == NOTOK
)
91 adios (maildir
, "unable to change directory to");
93 /* read folder and create message structure */
94 if (!(mp
= folder_read (folder
, 1)))
95 adios (NULL
, "unable to read folder %s", folder
);
98 * We need to make sure there is message status space
99 * for all the message numbers from 1 to "new" since
100 * mhpath can select empty slots. If we are adding
101 * space at the end, we go ahead and add 10 slots.
103 if (mp
->hghmsg
>= mp
->hghoff
) {
104 if (!(mp
= folder_realloc (mp
, 1, mp
->hghmsg
+ 10)))
105 adios (NULL
, "unable to allocate folder storage");
106 } else if (mp
->lowoff
> 1) {
107 if (!(mp
= folder_realloc (mp
, 1, mp
->hghoff
)))
108 adios (NULL
, "unable to allocate folder storage");
111 mp
->msgflags
|= ALLOW_NEW
; /* allow the "new" sequence */
113 /* parse all the message ranges/sequences and set SELECTED */
114 for (i
= 0; i
< msgs
.size
; i
++)
115 if (!m_convert (mp
, msgs
.msgs
[i
]))
118 seq_setprev (mp
); /* set the previous-sequence */
120 /* print the path of all selected messages */
121 for (i
= mp
->lowsel
; i
<= mp
->hghsel
; i
++)
122 if (is_selected (mp
, i
))
123 printf ("%s/%s\n", mp
->foldpath
, m_name (i
));
125 seq_save (mp
); /* synchronize message sequences */
126 context_save (); /* save the context file */
127 folder_free (mp
); /* free folder/message structure */