]>
diplodocus.org Git - nmh/blob - uip/mhpath.c
3 * mhpath.c -- print full pathnames of nmh messages and folders
7 * This code is Copyright (c) 2002, by the authors of nmh. See the
8 * COPYRIGHT file in the root directory of the nmh distribution for
9 * complete copyright information.
15 static struct swit switches
[] = {
24 main(int argc
, char **argv
)
27 char *cp
, *maildir
, *folder
= NULL
;
29 char **arguments
, buf
[BUFSIZ
];
30 struct msgs_array msgs
= { 0, 0, NULL
};
34 setlocale(LC_ALL
, "");
36 invo_name
= r1bindex (argv
[0], '/');
38 /* read user profile/context */
41 arguments
= getarguments (invo_name
, argc
, argv
, 1);
47 while ((cp
= *argp
++)) {
49 switch (smatch (++cp
, switches
)) {
51 ambigsw (cp
, switches
);
54 adios (NULL
, "-%s unknown", cp
);
57 snprintf (buf
, sizeof(buf
), "%s [+folder] [msgs] [switches]",
59 print_help (buf
, switches
, 1);
62 print_version(invo_name
);
66 if (*cp
== '+' || *cp
== '@') {
68 adios (NULL
, "only one folder at a time!");
70 folder
= pluspath (cp
);
72 app_msgarg(&msgs
, cp
);
75 if (!context_find ("path"))
76 free (path ("./", TFOLDER
));
79 folder
= getfolder (1);
80 maildir
= m_maildir (folder
);
82 /* If no messages are given, print folder pathname */
84 printf ("%s\n", maildir
);
88 if (chdir (maildir
) == NOTOK
)
89 adios (maildir
, "unable to change directory to");
91 /* read folder and create message structure */
92 if (!(mp
= folder_read (folder
)))
93 adios (NULL
, "unable to read folder %s", folder
);
96 * We need to make sure there is message status space
97 * for all the message numbers from 1 to "new" since
98 * mhpath can select empty slots. If we are adding
99 * space at the end, we go ahead and add 10 slots.
101 if (mp
->hghmsg
>= mp
->hghoff
) {
102 if (!(mp
= folder_realloc (mp
, 1, mp
->hghmsg
+ 10)))
103 adios (NULL
, "unable to allocate folder storage");
104 } else if (mp
->lowoff
> 1) {
105 if (!(mp
= folder_realloc (mp
, 1, mp
->hghoff
)))
106 adios (NULL
, "unable to allocate folder storage");
109 mp
->msgflags
|= ALLOW_NEW
; /* allow the "new" sequence */
111 /* parse all the message ranges/sequences and set SELECTED */
112 for (i
= 0; i
< msgs
.size
; i
++)
113 if (!m_convert (mp
, msgs
.msgs
[i
]))
116 seq_setprev (mp
); /* set the previous-sequence */
118 /* print the path of all selected messages */
119 for (i
= mp
->lowsel
; i
<= mp
->hghsel
; i
++)
120 if (is_selected (mp
, i
))
121 printf ("%s/%s\n", mp
->foldpath
, m_name (i
));
123 seq_save (mp
); /* synchronize message sequences */
124 context_save (); /* save the context file */
125 folder_free (mp
); /* free folder/message structure */