isync

mailbox synchronization program
git clone https://git.code.sf.net/p/isync/isync
Log | Files | Refs | README | LICENSE

commit bbbe88e07d09c28e549c40fbcde24a1ef04a6aa0
parent fa1e46f6ec7c0ed43e50e42671f7770862de454f
Author: Michael Elkins <me@mutt.org>
Date:   Thu, 21 Dec 2000 17:51:07 +0000

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

Diffstat:
Mconfigure.in | 2+-
Mmain.c | 27++++-----------------------
Msync.c | 20+++++++++++++-------
3 files changed, 18 insertions(+), 31 deletions(-)

diff --git a/configure.in b/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" diff --git a/main.c b/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); diff --git a/sync.c b/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 ("");