]>
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 static struct swit switches
[] = {
22 main(int argc
, char **argv
)
25 char *cp
, *maildir
, *folder
= NULL
;
27 char **arguments
, buf
[BUFSIZ
];
28 struct msgs_array msgs
= { 0, 0, NULL
};
32 setlocale(LC_ALL
, "");
34 invo_name
= r1bindex (argv
[0], '/');
36 /* read user profile/context */
39 arguments
= getarguments (invo_name
, argc
, argv
, 1);
45 while ((cp
= *argp
++)) {
47 switch (smatch (++cp
, switches
)) {
49 ambigsw (cp
, switches
);
52 adios (NULL
, "-%s unknown", cp
);
55 snprintf (buf
, sizeof(buf
), "%s [+folder] [msgs] [switches]",
57 print_help (buf
, switches
, 1);
60 print_version(invo_name
);
64 if (*cp
== '+' || *cp
== '@') {
66 adios (NULL
, "only one folder at a time!");
68 folder
= pluspath (cp
);
70 app_msgarg(&msgs
, cp
);
73 if (!context_find ("path"))
74 free (path ("./", TFOLDER
));
77 folder
= getfolder (1);
78 maildir
= m_maildir (folder
);
80 /* If no messages are given, print folder pathname */
82 printf ("%s\n", maildir
);
86 if (chdir (maildir
) == NOTOK
)
87 adios (maildir
, "unable to change directory to");
89 /* read folder and create message structure */
90 if (!(mp
= folder_read (folder
)))
91 adios (NULL
, "unable to read folder %s", folder
);
94 * We need to make sure there is message status space
95 * for all the message numbers from 1 to "new" since
96 * mhpath can select empty slots. If we are adding
97 * space at the end, we go ahead and add 10 slots.
99 if (mp
->hghmsg
>= mp
->hghoff
) {
100 if (!(mp
= folder_realloc (mp
, 1, mp
->hghmsg
+ 10)))
101 adios (NULL
, "unable to allocate folder storage");
102 } else if (mp
->lowoff
> 1) {
103 if (!(mp
= folder_realloc (mp
, 1, mp
->hghoff
)))
104 adios (NULL
, "unable to allocate folder storage");
107 mp
->msgflags
|= ALLOW_NEW
; /* allow the "new" sequence */
109 /* parse all the message ranges/sequences and set SELECTED */
110 for (i
= 0; i
< msgs
.size
; i
++)
111 if (!m_convert (mp
, msgs
.msgs
[i
]))
114 seq_setprev (mp
); /* set the previous-sequence */
116 /* print the path of all selected messages */
117 for (i
= mp
->lowsel
; i
<= mp
->hghsel
; i
++)
118 if (is_selected (mp
, i
))
119 printf ("%s/%s\n", mp
->foldpath
, m_name (i
));
121 seq_save (mp
); /* synchronize message sequences */
122 context_save (); /* save the context file */
123 folder_free (mp
); /* free folder/message structure */