Sfoglia il codice sorgente

use getpass() to get the user's password

unlink the temp file if we are unable to fetch a new message from the
server.

update version to 0.3
Michael Elkins 24 anni fa
parent
commit
bbbe88e07d
3 ha cambiato i file con 18 aggiunte e 31 eliminazioni
  1. 1 1
      configure.in
  2. 4 23
      main.c
  3. 13 7
      sync.c

+ 1 - 1
configure.in

@@ -1,5 +1,5 @@
 AC_INIT(isync.h)
-AM_INIT_AUTOMAKE(isync,0.2)
+AM_INIT_AUTOMAKE(isync,0.3)
 AM_PROG_CC_STDC
 if test $CC = gcc; then
 	CFLAGS="$CFLAGS -pipe"

+ 4 - 23
main.c

@@ -86,27 +86,6 @@ usage (void)
     exit (0);
 }
 
-static char *
-enter_password (void)
-{
-    struct termios t;
-    char pass[32];
-
-    tcgetattr (0, &t);
-    t.c_lflag &= ~ECHO;
-    tcsetattr (0, TCSANOW, &t);
-    printf ("Password: ");
-    fflush (stdout);
-    pass[sizeof (pass) - 1] = 0;
-    fgets (pass, sizeof (pass) - 1, stdin);
-    if (pass[0])
-	pass[strlen (pass) - 1] = 0;	/* kill newline */
-    t.c_lflag |= ECHO;
-    tcsetattr (0, TCSANOW, &t);
-    puts ("");
-    return strdup (pass);
-}
-
 /* set defaults from the global configuration section */
 static void
 config_defaults (config_t * conf)
@@ -383,12 +362,14 @@ main (int argc, char **argv)
 
     if (!box->pass)
     {
-	box->pass = enter_password ();
-	if (!box->pass)
+	char *pass = getpass ("Password:");
+
+	if (pass)
 	{
 	    puts ("Aborting, no password");
 	    exit (1);
 	}
+	box->pass = strdup (pass);
     }
 
     printf ("Reading %s\n", box->path);

+ 13 - 7
sync.c

@@ -47,6 +47,7 @@ sync_mailbox (mailbox_t * mbox, imap_t * imap, int flags)
     char newpath[_POSIX_PATH_MAX];
     char *p;
     int fd;
+    int ret;
 
     for (cur = mbox->msgs; cur; cur = cur->next)
     {
@@ -132,19 +133,24 @@ sync_mailbox (mailbox_t * mbox, imap_t * imap, int flags)
 		continue;
 	    }
 
-	    imap_fetch_message (imap, cur->uid, fd);
+	    ret = imap_fetch_message (imap, cur->uid, fd);
 
 	    close (fd);
 
-	    p = strrchr (path, '/');
+	    if (!ret)
+	    {
+		p = strrchr (path, '/');
 
-	    snprintf (newpath, sizeof (newpath), "%s/%s%s", mbox->path,
-		      (cur->flags & D_SEEN) ? "cur" : "new", p);
+		snprintf (newpath, sizeof (newpath), "%s/%s%s", mbox->path,
+			(cur->flags & D_SEEN) ? "cur" : "new", p);
 
-//          printf ("moving %s to %s\n", path, newpath);
+		//          printf ("moving %s to %s\n", path, newpath);
 
-	    if (rename (path, newpath))
-		perror ("rename");
+		if (rename (path, newpath))
+		    perror ("rename");
+	    }
+	    else
+		unlink(path);
 	}
     }
     puts ("");