changeset 23182:0ba967162ee0

[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).
author Karl Heuer <kwzh@gnu.org>
date Fri, 04 Sep 1998 20:14:16 +0000
parents 89d6facea3b5
children 3a0c163d32a6
files lib-src/movemail.c
diffstat 1 files changed, 32 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/lib-src/movemail.c	Fri Sep 04 20:08:58 1998 +0000
+++ b/lib-src/movemail.c	Fri Sep 04 20:14:16 1998 +0000
@@ -197,11 +197,23 @@
   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 @@
       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 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 @@
   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 @@
       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)