summaryrefslogtreecommitdiff
path: root/lib-src/movemail.c
diff options
context:
space:
mode:
authorKarl Heuer <kwzh@gnu.org>1998-09-04 20:14:16 +0000
committerKarl Heuer <kwzh@gnu.org>1998-09-04 20:14:16 +0000
commita2997b0f43237c7928f9c7ff36c4245243b42c9c (patch)
tree5a7e6dd260f6f4eeb2321bc1305c97372af4dd2c /lib-src/movemail.c
parent2c79f5b83167eef163568818b6cb17a8ada67abf (diff)
downloademacs-a2997b0f43237c7928f9c7ff36c4245243b42c9c.tar.gz
[MAIL_USE_POP]: Add the "-r" flag to reverse the
order of messages downloaded from a POP server (e.g., if the server stores messages in mailboxes in reverse order).
Diffstat (limited to 'lib-src/movemail.c')
-rw-r--r--lib-src/movemail.c36
1 files changed, 32 insertions, 4 deletions
diff --git a/lib-src/movemail.c b/lib-src/movemail.c
index 1ab59c0e5d2..45d6b5fe812 100644
--- a/lib-src/movemail.c
+++ b/lib-src/movemail.c
@@ -197,11 +197,23 @@ main (argc, argv)
char *spool_name;
#endif
+#ifdef MAIL_USE_POP
+ int pop_reverse_order = 0;
+# define ARGSTR "pr"
+#else /* ! MAIL_USE_POP */
+# define ARGSTR "p"
+#endif /* MAIL_USE_POP */
+
delete_lockname = 0;
- while ((c = getopt (argc, argv, "p")) != EOF)
+ while ((c = getopt (argc, argv, ARGSTR)) != EOF)
{
switch (c) {
+#ifdef MAIL_USE_POP
+ case 'r':
+ pop_reverse_order = 1;
+ break;
+#endif
case 'p':
preserve_mail++;
break;
@@ -263,7 +275,8 @@ main (argc, argv)
int status;
status = popmail (inname + 3, outname, preserve_mail,
- (argc - optind == 3) ? argv[optind+2] : NULL);
+ (argc - optind == 3) ? argv[optind+2] : NULL,
+ pop_reverse_order);
exit (status);
}
@@ -682,11 +695,12 @@ char ibuffer[BUFSIZ];
char obuffer[BUFSIZ];
char Errmsg[80];
-popmail (user, outfile, preserve, password)
+popmail (user, outfile, preserve, password, reverse_order)
char *user;
char *outfile;
int preserve;
char *password;
+ int reverse_order;
{
int nmsgs, nbytes;
register int i;
@@ -694,6 +708,7 @@ popmail (user, outfile, preserve, password)
FILE *mbf;
char *getenv ();
popserver server;
+ int start, end, increment;
server = pop_open (0, user, password, POP_NO_GETPASS);
if (! server)
@@ -732,7 +747,20 @@ popmail (user, outfile, preserve, password)
return (1);
}
- for (i = 1; i <= nmsgs; i++)
+ if (reverse_order)
+ {
+ start = nmsgs;
+ end = 1;
+ increment = -1;
+ }
+ else
+ {
+ start = 1;
+ end = nmsgs;
+ increment = 1;
+ }
+
+ for (i = start; i * increment <= end * increment; i += increment)
{
mbx_delimit_begin (mbf);
if (pop_retr (server, i, mbf) != OK)