@matheusbsbs / matheus-bagliano / commits / 95c539081e
Fork 0

imap-send.c: style fixes

Signed-off-by: Robert Shearman <robertshearman@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Robert Shearman committed Jul 9, 2008 at 22:29 UTC 95c539081e8519e00155c284ac7519727bbacc67
1 file changed +300 -329
imap-send.c
+300 -329
@@ -99,14 +99,14 @@ typedef struct {
99
100 static int Verbose, Quiet;
101
102 -static void imap_info( const char *, ... );
103 -static void imap_warn( const char *, ... );
102 +static void imap_info(const char *, ...);
103 +static void imap_warn(const char *, ...);
104
105 -static char *next_arg( char ** );
105 +static char *next_arg(char **);
106
107 -static void free_generic_messages( message_t * );
107 +static void free_generic_messages(message_t *);
108
109 -static int nfsnprintf( char *buf, int blen, const char *fmt, ... );
109 +static int nfsnprintf(char *buf, int blen, const char *fmt, ...);
110
111 static int nfvasprintf(char **strp, const char *fmt, va_list ap)
112 {
@@ -122,8 +122,8 @@ static int nfvasprintf(char **strp, const char *fmt, va_list ap)
122 return len;
123 }
124
125 -static void arc4_init( void );
126 -static unsigned char arc4_getbyte( void );
125 +static void arc4_init(void);
126 +static unsigned char arc4_getbyte(void);
127
128 typedef struct imap_server_conf {
129 char *name;
@@ -184,8 +184,8 @@ typedef struct imap_store {
184 } imap_store_t;
185
186 struct imap_cmd_cb {
187 - int (*cont)( imap_store_t *ctx, struct imap_cmd *cmd, const char *prompt );
188 - void (*done)( imap_store_t *ctx, struct imap_cmd *cmd, int response);
187 + int (*cont)(imap_store_t *ctx, struct imap_cmd *cmd, const char *prompt);
188 + void (*done)(imap_store_t *ctx, struct imap_cmd *cmd, int response);
189 void *ctx;
190 char *data;
191 int dlen;
@@ -222,7 +222,7 @@ static const char *cap_list[] = {
222 #define RESP_NO 1
223 #define RESP_BAD 2
224
225 -static int get_cmd_result( imap_store_t *ctx, struct imap_cmd *tcmd );
225 +static int get_cmd_result(imap_store_t *ctx, struct imap_cmd *tcmd);
226
227
228 static const char *Flags[] = {
@@ -240,8 +240,7 @@ static void ssl_socket_perror(const char *func)
240 }
241 #endif
242
243 -static void
244 -socket_perror( const char *func, Socket_t *sock, int ret )
243 +static void socket_perror(const char *func, Socket_t *sock, int ret)
244 {
245 #ifndef NO_OPENSSL
246 if (sock->ssl) {
@@ -318,8 +317,7 @@ static int ssl_socket_connect(Socket_t *sock, int use_tls_only, int verify)
317 #endif
318 }
319
321 -static int
322 -socket_read( Socket_t *sock, char *buf, int len )
320 +static int socket_read(Socket_t *sock, char *buf, int len)
321 {
322 ssize_t n;
323 #ifndef NO_OPENSSL
@@ -327,17 +325,16 @@ socket_read( Socket_t *sock, char *buf, int len )
325 n = SSL_read(sock->ssl, buf, len);
326 else
327 #endif
330 - n = xread( sock->fd, buf, len );
328 + n = xread(sock->fd, buf, len);
329 if (n <= 0) {
332 - socket_perror( "read", sock, n );
333 - close( sock->fd );
330 + socket_perror("read", sock, n);
331 + close(sock->fd);
332 sock->fd = -1;
333 }
334 return n;
335 }
336
339 -static int
340 -socket_write( Socket_t *sock, const char *buf, int len )
337 +static int socket_write(Socket_t *sock, const char *buf, int len)
338 {
339 int n;
340 #ifndef NO_OPENSSL
@@ -345,10 +342,10 @@ socket_write( Socket_t *sock, const char *buf, int len )
342 n = SSL_write(sock->ssl, buf, len);
343 else
344 #endif
348 - n = write_in_full( sock->fd, buf, len );
345 + n = write_in_full(sock->fd, buf, len);
346 if (n != len) {
350 - socket_perror( "write", sock, n );
351 - close( sock->fd );
347 + socket_perror("write", sock, n);
348 + close(sock->fd);
349 sock->fd = -1;
350 }
351 return n;
@@ -366,8 +363,7 @@ static void socket_shutdown(Socket_t *sock)
363 }
364
365 /* simple line buffering */
369 -static int
370 -buffer_gets( buffer_t * b, char **s )
366 +static int buffer_gets(buffer_t * b, char **s)
367 {
368 int n;
369 int start = b->offset;
@@ -381,7 +377,7 @@ buffer_gets( buffer_t * b, char **s )
377 /* shift down used bytes */
378 *s = b->buf;
379
384 - assert( start <= b->bytes );
380 + assert(start <= b->bytes);
381 n = b->bytes - start;
382
383 if (n)
@@ -391,8 +387,8 @@ buffer_gets( buffer_t * b, char **s )
387 start = 0;
388 }
389
394 - n = socket_read( &b->sock, b->buf + b->bytes,
395 - sizeof(b->buf) - b->bytes );
390 + n = socket_read(&b->sock, b->buf + b->bytes,
391 + sizeof(b->buf) - b->bytes);
392
393 if (n <= 0)
394 return -1;
@@ -401,12 +397,12 @@ buffer_gets( buffer_t * b, char **s )
397 }
398
399 if (b->buf[b->offset] == '\r') {
404 - assert( b->offset + 1 < b->bytes );
400 + assert(b->offset + 1 < b->bytes);
401 if (b->buf[b->offset + 1] == '\n') {
402 b->buf[b->offset] = 0; /* terminate the string */
403 b->offset += 2; /* next line */
404 if (Verbose)
409 - puts( *s );
405 + puts(*s);
406 return 0;
407 }
408 }
@@ -416,39 +412,36 @@ buffer_gets( buffer_t * b, char **s )
412 /* not reached */
413 }
414
419 -static void
420 -imap_info( const char *msg, ... )
415 +static void imap_info(const char *msg, ...)
416 {
417 va_list va;
418
419 if (!Quiet) {
425 - va_start( va, msg );
426 - vprintf( msg, va );
427 - va_end( va );
428 - fflush( stdout );
420 + va_start(va, msg);
421 + vprintf(msg, va);
422 + va_end(va);
423 + fflush(stdout);
424 }
425 }
426
432 -static void
433 -imap_warn( const char *msg, ... )
427 +static void imap_warn(const char *msg, ...)
428 {
429 va_list va;
430
431 if (Quiet < 2) {
438 - va_start( va, msg );
439 - vfprintf( stderr, msg, va );
440 - va_end( va );
432 + va_start(va, msg);
433 + vfprintf(stderr, msg, va);
434 + va_end(va);
435 }
436 }
437
444 -static char *
445 -next_arg( char **s )
438 +static char *next_arg(char **s)
439 {
440 char *ret;
441
442 if (!s || !*s)
443 return NULL;
451 - while (isspace( (unsigned char) **s ))
444 + while (isspace((unsigned char) **s))
445 (*s)++;
446 if (!**s) {
447 *s = NULL;
@@ -457,10 +450,10 @@ next_arg( char **s )
450 if (**s == '"') {
451 ++*s;
452 ret = *s;
460 - *s = strchr( *s, '"' );
453 + *s = strchr(*s, '"');
454 } else {
455 ret = *s;
463 - while (**s && !isspace( (unsigned char) **s ))
456 + while (**s && !isspace((unsigned char) **s))
457 (*s)++;
458 }
459 if (*s) {
@@ -472,27 +465,25 @@ next_arg( char **s )
465 return ret;
466 }
467
475 -static void
476 -free_generic_messages( message_t *msgs )
468 +static void free_generic_messages(message_t *msgs)
469 {
470 message_t *tmsg;
471
472 for (; msgs; msgs = tmsg) {
473 tmsg = msgs->next;
482 - free( msgs );
474 + free(msgs);
475 }
476 }
477
486 -static int
487 -nfsnprintf( char *buf, int blen, const char *fmt, ... )
478 +static int nfsnprintf(char *buf, int blen, const char *fmt, ...)
479 {
480 int ret;
481 va_list va;
482
492 - va_start( va, fmt );
493 - if (blen <= 0 || (unsigned)(ret = vsnprintf( buf, blen, fmt, va )) >= (unsigned)blen)
494 - die( "Fatal: buffer too small. Please report a bug.\n");
495 - va_end( va );
483 + va_start(va, fmt);
484 + if (blen <= 0 || (unsigned)(ret = vsnprintf(buf, blen, fmt, va)) >= (unsigned)blen)
485 + die("Fatal: buffer too small. Please report a bug.\n");
486 + va_end(va);
487 return ret;
488 }
489
@@ -500,21 +491,20 @@ static struct {
491 unsigned char i, j, s[256];
492 } rs;
493
503 -static void
504 -arc4_init( void )
494 +static void arc4_init(void)
495 {
496 int i, fd;
497 unsigned char j, si, dat[128];
498
509 - if ((fd = open( "/dev/urandom", O_RDONLY )) < 0 && (fd = open( "/dev/random", O_RDONLY )) < 0) {
510 - fprintf( stderr, "Fatal: no random number source available.\n" );
511 - exit( 3 );
499 + if ((fd = open("/dev/urandom", O_RDONLY)) < 0 && (fd = open("/dev/random", O_RDONLY)) < 0) {
500 + fprintf(stderr, "Fatal: no random number source available.\n");
501 + exit(3);
502 }
513 - if (read_in_full( fd, dat, 128 ) != 128) {
514 - fprintf( stderr, "Fatal: cannot read random number source.\n" );
515 - exit( 3 );
503 + if (read_in_full(fd, dat, 128) != 128) {
504 + fprintf(stderr, "Fatal: cannot read random number source.\n");
505 + exit(3);
506 }
517 - close( fd );
507 + close(fd);
508
509 for (i = 0; i < 256; i++)
510 rs.s[i] = i;
@@ -530,8 +520,7 @@ arc4_init( void )
520 arc4_getbyte();
521 }
522
533 -static unsigned char
534 -arc4_getbyte( void )
523 +static unsigned char arc4_getbyte(void)
524 {
525 unsigned char si, sj;
526
@@ -544,54 +533,54 @@ arc4_getbyte( void )
533 return rs.s[(si + sj) & 0xff];
534 }
535
547 -static struct imap_cmd *
548 -v_issue_imap_cmd( imap_store_t *ctx, struct imap_cmd_cb *cb,
549 - const char *fmt, va_list ap )
536 +static struct imap_cmd *v_issue_imap_cmd(imap_store_t *ctx,
537 + struct imap_cmd_cb *cb,
538 + const char *fmt, va_list ap)
539 {
540 imap_t *imap = ctx->imap;
541 struct imap_cmd *cmd;
542 int n, bufl;
543 char buf[1024];
544
556 - cmd = xmalloc( sizeof(struct imap_cmd) );
557 - nfvasprintf( &cmd->cmd, fmt, ap );
545 + cmd = xmalloc(sizeof(struct imap_cmd));
546 + nfvasprintf(&cmd->cmd, fmt, ap);
547 cmd->tag = ++imap->nexttag;
548
549 if (cb)
550 cmd->cb = *cb;
551 else
563 - memset( &cmd->cb, 0, sizeof(cmd->cb) );
552 + memset(&cmd->cb, 0, sizeof(cmd->cb));
553
554 while (imap->literal_pending)
566 - get_cmd_result( ctx, NULL );
555 + get_cmd_result(ctx, NULL);
556
568 - bufl = nfsnprintf( buf, sizeof(buf), cmd->cb.data ? CAP(LITERALPLUS) ?
557 + bufl = nfsnprintf(buf, sizeof(buf), cmd->cb.data ? CAP(LITERALPLUS) ?
558 "%d %s{%d+}\r\n" : "%d %s{%d}\r\n" : "%d %s\r\n",
570 - cmd->tag, cmd->cmd, cmd->cb.dlen );
559 + cmd->tag, cmd->cmd, cmd->cb.dlen);
560 if (Verbose) {
561 if (imap->num_in_progress)
573 - printf( "(%d in progress) ", imap->num_in_progress );
574 - if (memcmp( cmd->cmd, "LOGIN", 5 ))
575 - printf( ">>> %s", buf );
562 + printf("(%d in progress) ", imap->num_in_progress);
563 + if (memcmp(cmd->cmd, "LOGIN", 5))
564 + printf(">>> %s", buf);
565 else
577 - printf( ">>> %d LOGIN <user> <pass>\n", cmd->tag );
566 + printf(">>> %d LOGIN <user> <pass>\n", cmd->tag);
567 }
579 - if (socket_write( &imap->buf.sock, buf, bufl ) != bufl) {
580 - free( cmd->cmd );
581 - free( cmd );
568 + if (socket_write(&imap->buf.sock, buf, bufl) != bufl) {
569 + free(cmd->cmd);
570 + free(cmd);
571 if (cb)
583 - free( cb->data );
572 + free(cb->data);
573 return NULL;
574 }
575 if (cmd->cb.data) {
576 if (CAP(LITERALPLUS)) {
588 - n = socket_write( &imap->buf.sock, cmd->cb.data, cmd->cb.dlen );
589 - free( cmd->cb.data );
577 + n = socket_write(&imap->buf.sock, cmd->cb.data, cmd->cb.dlen);
578 + free(cmd->cb.data);
579 if (n != cmd->cb.dlen ||
591 - (n = socket_write( &imap->buf.sock, "\r\n", 2 )) != 2)
580 + (n = socket_write(&imap->buf.sock, "\r\n", 2)) != 2)
581 {
593 - free( cmd->cmd );
594 - free( cmd );
582 + free(cmd->cmd);
583 + free(cmd);
584 return NULL;
585 }
586 cmd->cb.data = NULL;
@@ -606,109 +595,106 @@ v_issue_imap_cmd( imap_store_t *ctx, struct imap_cmd_cb *cb,
595 return cmd;
596 }
597
609 -static struct imap_cmd *
610 -issue_imap_cmd( imap_store_t *ctx, struct imap_cmd_cb *cb, const char *fmt, ... )
598 +static struct imap_cmd *issue_imap_cmd(imap_store_t *ctx,
599 + struct imap_cmd_cb *cb,
600 + const char *fmt, ...)
601 {
602 struct imap_cmd *ret;
603 va_list ap;
604
615 - va_start( ap, fmt );
616 - ret = v_issue_imap_cmd( ctx, cb, fmt, ap );
617 - va_end( ap );
605 + va_start(ap, fmt);
606 + ret = v_issue_imap_cmd(ctx, cb, fmt, ap);
607 + va_end(ap);
608 return ret;
609 }
610
621 -static int
622 -imap_exec( imap_store_t *ctx, struct imap_cmd_cb *cb, const char *fmt, ... )
611 +static int imap_exec(imap_store_t *ctx, struct imap_cmd_cb *cb,
612 + const char *fmt, ...)
613 {
614 va_list ap;
615 struct imap_cmd *cmdp;
616
627 - va_start( ap, fmt );
628 - cmdp = v_issue_imap_cmd( ctx, cb, fmt, ap );
629 - va_end( ap );
617 + va_start(ap, fmt);
618 + cmdp = v_issue_imap_cmd(ctx, cb, fmt, ap);
619 + va_end(ap);
620 if (!cmdp)
621 return RESP_BAD;
622
633 - return get_cmd_result( ctx, cmdp );
623 + return get_cmd_result(ctx, cmdp);
624 }
625
636 -static int
637 -imap_exec_m( imap_store_t *ctx, struct imap_cmd_cb *cb, const char *fmt, ... )
626 +static int imap_exec_m(imap_store_t *ctx, struct imap_cmd_cb *cb,
627 + const char *fmt, ...)
628 {
629 va_list ap;
630 struct imap_cmd *cmdp;
631
642 - va_start( ap, fmt );
643 - cmdp = v_issue_imap_cmd( ctx, cb, fmt, ap );
644 - va_end( ap );
632 + va_start(ap, fmt);
633 + cmdp = v_issue_imap_cmd(ctx, cb, fmt, ap);
634 + va_end(ap);
635 if (!cmdp)
636 return DRV_STORE_BAD;
637
648 - switch (get_cmd_result( ctx, cmdp )) {
638 + switch (get_cmd_result(ctx, cmdp)) {
639 case RESP_BAD: return DRV_STORE_BAD;
640 case RESP_NO: return DRV_MSG_BAD;
641 default: return DRV_OK;
642 }
643 }
644
655 -static int
656 -is_atom( list_t *list )
645 +static int is_atom(list_t *list)
646 {
647 return list && list->val && list->val != NIL && list->val != LIST;
648 }
649
661 -static int
662 -is_list( list_t *list )
650 +static int is_list(list_t *list)
651 {
652 return list && list->val == LIST;
653 }
654
667 -static void
668 -free_list( list_t *list )
655 +static void free_list(list_t *list)
656 {
657 list_t *tmp;
658
659 for (; list; list = tmp) {
660 tmp = list->next;
674 - if (is_list( list ))
675 - free_list( list->child );
676 - else if (is_atom( list ))
677 - free( list->val );
678 - free( list );
661 + if (is_list(list))
662 + free_list(list->child);
663 + else if (is_atom(list))
664 + free(list->val);
665 + free(list);
666 }
667 }
668
682 -static int
683 -parse_imap_list_l( imap_t *imap, char **sp, list_t **curp, int level )
669 +static int parse_imap_list_l(imap_t *imap, char **sp, list_t **curp, int level)
670 {
671 list_t *cur;
672 char *s = *sp, *p;
673 int n, bytes;
674
675 for (;;) {
690 - while (isspace( (unsigned char)*s ))
676 + while (isspace((unsigned char)*s))
677 s++;
678 if (level && *s == ')') {
679 s++;
680 break;
681 }
696 - *curp = cur = xmalloc( sizeof(*cur) );
682 + *curp = cur = xmalloc(sizeof(*cur));
683 curp = &cur->next;
684 cur->val = NULL; /* for clean bail */
685 if (*s == '(') {
686 /* sublist */
687 s++;
688 cur->val = LIST;
703 - if (parse_imap_list_l( imap, &s, &cur->child, level + 1 ))
689 + if (parse_imap_list_l(imap, &s, &cur->child, level + 1))
690 goto bail;
691 } else if (imap && *s == '{') {
692 /* literal */
707 - bytes = cur->len = strtol( s + 1, &s, 10 );
693 + bytes = cur->len = strtol(s + 1, &s, 10);
694 if (*s != '}')
695 goto bail;
696
711 - s = cur->val = xmalloc( cur->len );
697 + s = cur->val = xmalloc(cur->len);
698
699 /* dump whats left over in the input buffer */
700 n = imap->buf.bytes - imap->buf.offset;
@@ -717,7 +703,7 @@ parse_imap_list_l( imap_t *imap, char **sp, list_t **curp, int level )
703 /* the entire message fit in the buffer */
704 n = bytes;
705
720 - memcpy( s, imap->buf.buf + imap->buf.offset, n );
706 + memcpy(s, imap->buf.buf + imap->buf.offset, n);
707 s += n;
708 bytes -= n;
709
@@ -726,13 +712,13 @@ parse_imap_list_l( imap_t *imap, char **sp, list_t **curp, int level )
712
713 /* now read the rest of the message */
714 while (bytes > 0) {
729 - if ((n = socket_read (&imap->buf.sock, s, bytes)) <= 0)
715 + if ((n = socket_read(&imap->buf.sock, s, bytes)) <= 0)
716 goto bail;
717 s += n;
718 bytes -= n;
719 }
720
735 - if (buffer_gets( &imap->buf, &s ))
721 + if (buffer_gets(&imap->buf, &s))
722 goto bail;
723 } else if (*s == '"') {
724 /* quoted string */
@@ -747,11 +733,11 @@ parse_imap_list_l( imap_t *imap, char **sp, list_t **curp, int level )
733 } else {
734 /* atom */
735 p = s;
750 - for (; *s && !isspace( (unsigned char)*s ); s++)
736 + for (; *s && !isspace((unsigned char)*s); s++)
737 if (level && *s == ')')
738 break;
739 cur->len = s - p;
754 - if (cur->len == 3 && !memcmp ("NIL", p, 3)) {
740 + if (cur->len == 3 && !memcmp("NIL", p, 3)) {
741 cur->val = NIL;
742 } else {
743 cur->val = xmemdupz(p, cur->len);
@@ -772,39 +758,36 @@ parse_imap_list_l( imap_t *imap, char **sp, list_t **curp, int level )
758 return -1;
759 }
760
775 -static list_t *
776 -parse_imap_list( imap_t *imap, char **sp )
761 +static list_t *parse_imap_list(imap_t *imap, char **sp)
762 {
763 list_t *head;
764
780 - if (!parse_imap_list_l( imap, sp, &head, 0 ))
765 + if (!parse_imap_list_l(imap, sp, &head, 0))
766 return head;
782 - free_list( head );
767 + free_list(head);
768 return NULL;
769 }
770
786 -static list_t *
787 -parse_list( char **sp )
771 +static list_t *parse_list(char **sp)
772 {
789 - return parse_imap_list( NULL, sp );
773 + return parse_imap_list(NULL, sp);
774 }
775
792 -static void
793 -parse_capability( imap_t *imap, char *cmd )
776 +static void parse_capability(imap_t *imap, char *cmd)
777 {
778 char *arg;
779 unsigned i;
780
781 imap->caps = 0x80000000;
799 - while ((arg = next_arg( &cmd )))
782 + while ((arg = next_arg(&cmd)))
783 for (i = 0; i < ARRAY_SIZE(cap_list); i++)
801 - if (!strcmp( cap_list[i], arg ))
784 + if (!strcmp(cap_list[i], arg))
785 imap->caps |= 1 << i;
786 imap->rcaps = imap->caps;
787 }
788
806 -static int
807 -parse_response_code( imap_store_t *ctx, struct imap_cmd_cb *cb, char *s )
789 +static int parse_response_code(imap_store_t *ctx, struct imap_cmd_cb *cb,
790 + char *s)
791 {
792 imap_t *imap = ctx->imap;
793 char *arg, *p;
@@ -812,43 +795,42 @@ parse_response_code( imap_store_t *ctx, struct imap_cmd_cb *cb, char *s )
795 if (*s != '[')
796 return RESP_OK; /* no response code */
797 s++;
815 - if (!(p = strchr( s, ']' ))) {
816 - fprintf( stderr, "IMAP error: malformed response code\n" );
798 + if (!(p = strchr(s, ']'))) {
799 + fprintf(stderr, "IMAP error: malformed response code\n");
800 return RESP_BAD;
801 }
802 *p++ = 0;
820 - arg = next_arg( &s );
821 - if (!strcmp( "UIDVALIDITY", arg )) {
822 - if (!(arg = next_arg( &s )) || !(ctx->gen.uidvalidity = atoi( arg ))) {
823 - fprintf( stderr, "IMAP error: malformed UIDVALIDITY status\n" );
803 + arg = next_arg(&s);
804 + if (!strcmp("UIDVALIDITY", arg)) {
805 + if (!(arg = next_arg(&s)) || !(ctx->gen.uidvalidity = atoi(arg))) {
806 + fprintf(stderr, "IMAP error: malformed UIDVALIDITY status\n");
807 return RESP_BAD;
808 }
826 - } else if (!strcmp( "UIDNEXT", arg )) {
827 - if (!(arg = next_arg( &s )) || !(imap->uidnext = atoi( arg ))) {
828 - fprintf( stderr, "IMAP error: malformed NEXTUID status\n" );
809 + } else if (!strcmp("UIDNEXT", arg)) {
810 + if (!(arg = next_arg(&s)) || !(imap->uidnext = atoi(arg))) {
811 + fprintf(stderr, "IMAP error: malformed NEXTUID status\n");
812 return RESP_BAD;
813 }
831 - } else if (!strcmp( "CAPABILITY", arg )) {
832 - parse_capability( imap, s );
833 - } else if (!strcmp( "ALERT", arg )) {
814 + } else if (!strcmp("CAPABILITY", arg)) {
815 + parse_capability(imap, s);
816 + } else if (!strcmp("ALERT", arg)) {
817 /* RFC2060 says that these messages MUST be displayed
818 * to the user
819 */
837 - for (; isspace( (unsigned char)*p ); p++);
838 - fprintf( stderr, "*** IMAP ALERT *** %s\n", p );
839 - } else if (cb && cb->ctx && !strcmp( "APPENDUID", arg )) {
840 - if (!(arg = next_arg( &s )) || !(ctx->gen.uidvalidity = atoi( arg )) ||
841 - !(arg = next_arg( &s )) || !(*(int *)cb->ctx = atoi( arg )))
820 + for (; isspace((unsigned char)*p); p++);
821 + fprintf(stderr, "*** IMAP ALERT *** %s\n", p);
822 + } else if (cb && cb->ctx && !strcmp("APPENDUID", arg)) {
823 + if (!(arg = next_arg(&s)) || !(ctx->gen.uidvalidity = atoi(arg)) ||
824 + !(arg = next_arg(&s)) || !(*(int *)cb->ctx = atoi(arg)))
825 {
843 - fprintf( stderr, "IMAP error: malformed APPENDUID status\n" );
826 + fprintf(stderr, "IMAP error: malformed APPENDUID status\n");
827 return RESP_BAD;
828 }
829 }
830 return RESP_OK;
831 }
832
850 -static int
851 -get_cmd_result( imap_store_t *ctx, struct imap_cmd *tcmd )
833 +static int get_cmd_result(imap_store_t *ctx, struct imap_cmd *tcmd)
834 {
835 imap_t *imap = ctx->imap;
836 struct imap_cmd *cmdp, **pcmdp, *ncmdp;
@@ -856,38 +838,38 @@ get_cmd_result( imap_store_t *ctx, struct imap_cmd *tcmd )
838 int n, resp, resp2, tag;
839
840 for (;;) {
859 - if (buffer_gets( &imap->buf, &cmd ))
841 + if (buffer_gets(&imap->buf, &cmd))
842 return RESP_BAD;
843
862 - arg = next_arg( &cmd );
844 + arg = next_arg(&cmd);
845 if (*arg == '*') {
864 - arg = next_arg( &cmd );
846 + arg = next_arg(&cmd);
847 if (!arg) {
866 - fprintf( stderr, "IMAP error: unable to parse untagged response\n" );
848 + fprintf(stderr, "IMAP error: unable to parse untagged response\n");
849 return RESP_BAD;
850 }
851
870 - if (!strcmp( "NAMESPACE", arg )) {
871 - imap->ns_personal = parse_list( &cmd );
872 - imap->ns_other = parse_list( &cmd );
873 - imap->ns_shared = parse_list( &cmd );
874 - } else if (!strcmp( "OK", arg ) || !strcmp( "BAD", arg ) ||
875 - !strcmp( "NO", arg ) || !strcmp( "BYE", arg )) {
876 - if ((resp = parse_response_code( ctx, NULL, cmd )) != RESP_OK)
852 + if (!strcmp("NAMESPACE", arg)) {
853 + imap->ns_personal = parse_list(&cmd);
854 + imap->ns_other = parse_list(&cmd);
855 + imap->ns_shared = parse_list(&cmd);
856 + } else if (!strcmp("OK", arg) || !strcmp("BAD", arg) ||
857 + !strcmp("NO", arg) || !strcmp("BYE", arg)) {
858 + if ((resp = parse_response_code(ctx, NULL, cmd)) != RESP_OK)
859 return resp;
878 - } else if (!strcmp( "CAPABILITY", arg ))
879 - parse_capability( imap, cmd );
880 - else if ((arg1 = next_arg( &cmd ))) {
881 - if (!strcmp( "EXISTS", arg1 ))
882 - ctx->gen.count = atoi( arg );
883 - else if (!strcmp( "RECENT", arg1 ))
884 - ctx->gen.recent = atoi( arg );
860 + } else if (!strcmp("CAPABILITY", arg))
861 + parse_capability(imap, cmd);
862 + else if ((arg1 = next_arg(&cmd))) {
863 + if (!strcmp("EXISTS", arg1))
864 + ctx->gen.count = atoi(arg);
865 + else if (!strcmp("RECENT", arg1))
866 + ctx->gen.recent = atoi(arg);
867 } else {
886 - fprintf( stderr, "IMAP error: unable to parse untagged response\n" );
868 + fprintf(stderr, "IMAP error: unable to parse untagged response\n");
869 return RESP_BAD;
870 }
871 } else if (!imap->in_progress) {
890 - fprintf( stderr, "IMAP error: unexpected reply: %s %s\n", arg, cmd ? cmd : "" );
872 + fprintf(stderr, "IMAP error: unexpected reply: %s %s\n", arg, cmd ? cmd : "");
873 return RESP_BAD;
874 } else if (*arg == '+') {
875 /* This can happen only with the last command underway, as
@@ -895,30 +877,30 @@ get_cmd_result( imap_store_t *ctx, struct imap_cmd *tcmd )
877 cmdp = (struct imap_cmd *)((char *)imap->in_progress_append -
878 offsetof(struct imap_cmd, next));
879 if (cmdp->cb.data) {
898 - n = socket_write( &imap->buf.sock, cmdp->cb.data, cmdp->cb.dlen );
899 - free( cmdp->cb.data );
880 + n = socket_write(&imap->buf.sock, cmdp->cb.data, cmdp->cb.dlen);
881 + free(cmdp->cb.data);
882 cmdp->cb.data = NULL;
883 if (n != (int)cmdp->cb.dlen)
884 return RESP_BAD;
885 } else if (cmdp->cb.cont) {
904 - if (cmdp->cb.cont( ctx, cmdp, cmd ))
886 + if (cmdp->cb.cont(ctx, cmdp, cmd))
887 return RESP_BAD;
888 } else {
907 - fprintf( stderr, "IMAP error: unexpected command continuation request\n" );
889 + fprintf(stderr, "IMAP error: unexpected command continuation request\n");
890 return RESP_BAD;
891 }
910 - if (socket_write( &imap->buf.sock, "\r\n", 2 ) != 2)
892 + if (socket_write(&imap->buf.sock, "\r\n", 2) != 2)
893 return RESP_BAD;
894 if (!cmdp->cb.cont)
895 imap->literal_pending = 0;
896 if (!tcmd)
897 return DRV_OK;
898 } else {
917 - tag = atoi( arg );
899 + tag = atoi(arg);
900 for (pcmdp = &imap->in_progress; (cmdp = *pcmdp); pcmdp = &cmdp->next)
901 if (cmdp->tag == tag)
902 goto gottag;
921 - fprintf( stderr, "IMAP error: unexpected tag %s\n", arg );
903 + fprintf(stderr, "IMAP error: unexpected tag %s\n", arg);
904 return RESP_BAD;
905 gottag:
906 if (!(*pcmdp = cmdp->next))
@@ -926,26 +908,26 @@ get_cmd_result( imap_store_t *ctx, struct imap_cmd *tcmd )
908 imap->num_in_progress--;
909 if (cmdp->cb.cont || cmdp->cb.data)
910 imap->literal_pending = 0;
929 - arg = next_arg( &cmd );
930 - if (!strcmp( "OK", arg ))
911 + arg = next_arg(&cmd);
912 + if (!strcmp("OK", arg))
913 resp = DRV_OK;
914 else {
933 - if (!strcmp( "NO", arg )) {
934 - if (cmdp->cb.create && cmd && (cmdp->cb.trycreate || !memcmp( cmd, "[TRYCREATE]", 11 ))) { /* SELECT, APPEND or UID COPY */
935 - p = strchr( cmdp->cmd, '"' );
936 - if (!issue_imap_cmd( ctx, NULL, "CREATE \"%.*s\"", strchr( p + 1, '"' ) - p + 1, p )) {
915 + if (!strcmp("NO", arg)) {
916 + if (cmdp->cb.create && cmd && (cmdp->cb.trycreate || !memcmp(cmd, "[TRYCREATE]", 11))) { /* SELECT, APPEND or UID COPY */
917 + p = strchr(cmdp->cmd, '"');
918 + if (!issue_imap_cmd(ctx, NULL, "CREATE \"%.*s\"", strchr(p + 1, '"') - p + 1, p)) {
919 resp = RESP_BAD;
920 goto normal;
921 }
922 /* not waiting here violates the spec, but a server that does not
923 grok this nonetheless violates it too. */
924 cmdp->cb.create = 0;
943 - if (!(ncmdp = issue_imap_cmd( ctx, &cmdp->cb, "%s", cmdp->cmd ))) {
925 + if (!(ncmdp = issue_imap_cmd(ctx, &cmdp->cb, "%s", cmdp->cmd))) {
926 resp = RESP_BAD;
927 goto normal;
928 }
947 - free( cmdp->cmd );
948 - free( cmdp );
929 + free(cmdp->cmd);
930 + free(cmdp);
931 if (!tcmd)
932 return 0; /* ignored */
933 if (cmdp == tcmd)
@@ -953,21 +935,21 @@ get_cmd_result( imap_store_t *ctx, struct imap_cmd *tcmd )
935 continue;
936 }
937 resp = RESP_NO;
956 - } else /*if (!strcmp( "BAD", arg ))*/
938 + } else /*if (!strcmp("BAD", arg))*/
939 resp = RESP_BAD;
958 - fprintf( stderr, "IMAP command '%s' returned response (%s) - %s\n",
959 - memcmp (cmdp->cmd, "LOGIN", 5) ?
940 + fprintf(stderr, "IMAP command '%s' returned response (%s) - %s\n",
941 + memcmp(cmdp->cmd, "LOGIN", 5) ?
942 cmdp->cmd : "LOGIN <user> <pass>",
943 arg, cmd ? cmd : "");
944 }
963 - if ((resp2 = parse_response_code( ctx, &cmdp->cb, cmd )) > resp)
945 + if ((resp2 = parse_response_code(ctx, &cmdp->cb, cmd)) > resp)
946 resp = resp2;
947 normal:
948 if (cmdp->cb.done)
967 - cmdp->cb.done( ctx, cmdp, resp );
968 - free( cmdp->cb.data );
969 - free( cmdp->cmd );
970 - free( cmdp );
949 + cmdp->cb.done(ctx, cmdp, resp);
950 + free(cmdp->cb.data);
951 + free(cmdp->cmd);
952 + free(cmdp);
953 if (!tcmd || tcmd == cmdp)
954 return resp;
955 }
@@ -975,31 +957,28 @@ get_cmd_result( imap_store_t *ctx, struct imap_cmd *tcmd )
957 /* not reached */
958 }
959
978 -static void
979 -imap_close_server( imap_store_t *ictx )
960 +static void imap_close_server(imap_store_t *ictx)
961 {
962 imap_t *imap = ictx->imap;
963
964 if (imap->buf.sock.fd != -1) {
984 - imap_exec( ictx, NULL, "LOGOUT" );
985 - socket_shutdown( &imap->buf.sock );
965 + imap_exec(ictx, NULL, "LOGOUT");
966 + socket_shutdown(&imap->buf.sock);
967 }
987 - free_list( imap->ns_personal );
988 - free_list( imap->ns_other );
989 - free_list( imap->ns_shared );
990 - free( imap );
968 + free_list(imap->ns_personal);
969 + free_list(imap->ns_other);
970 + free_list(imap->ns_shared);
971 + free(imap);
972 }
973
993 -static void
994 -imap_close_store( store_t *ctx )
974 +static void imap_close_store(store_t *ctx)
975 {
996 - imap_close_server( (imap_store_t *)ctx );
997 - free_generic_messages( ctx->msgs );
998 - free( ctx );
976 + imap_close_server((imap_store_t *)ctx);
977 + free_generic_messages(ctx->msgs);
978 + free(ctx);
979 }
980
1001 -static store_t *
1002 -imap_open_store( imap_server_conf_t *srvc )
981 +static store_t *imap_open_store(imap_server_conf_t *srvc)
982 {
983 imap_store_t *ctx;
984 imap_t *imap;
@@ -1009,60 +988,60 @@ imap_open_store( imap_server_conf_t *srvc )
988 int s, a[2], preauth;
989 pid_t pid;
990
1012 - ctx = xcalloc( sizeof(*ctx), 1 );
991 + ctx = xcalloc(sizeof(*ctx), 1);
992
1014 - ctx->imap = imap = xcalloc( sizeof(*imap), 1 );
993 + ctx->imap = imap = xcalloc(sizeof(*imap), 1);
994 imap->buf.sock.fd = -1;
995 imap->in_progress_append = &imap->in_progress;
996
997 /* open connection to IMAP server */
998
999 if (srvc->tunnel) {
1021 - imap_info( "Starting tunnel '%s'... ", srvc->tunnel );
1000 + imap_info("Starting tunnel '%s'... ", srvc->tunnel);
1001
1023 - if (socketpair( PF_UNIX, SOCK_STREAM, 0, a )) {
1024 - perror( "socketpair" );
1025 - exit( 1 );
1002 + if (socketpair(PF_UNIX, SOCK_STREAM, 0, a)) {
1003 + perror("socketpair");
1004 + exit(1);
1005 }
1006
1007 pid = fork();
1008 if (pid < 0)
1030 - _exit( 127 );
1009 + _exit(127);
1010 if (!pid) {
1032 - if (dup2( a[0], 0 ) == -1 || dup2( a[0], 1 ) == -1)
1033 - _exit( 127 );
1034 - close( a[0] );
1035 - close( a[1] );
1036 - execl( "/bin/sh", "sh", "-c", srvc->tunnel, NULL );
1037 - _exit( 127 );
1011 + if (dup2(a[0], 0) == -1 || dup2(a[0], 1) == -1)
1012 + _exit(127);
1013 + close(a[0]);
1014 + close(a[1]);
1015 + execl("/bin/sh", "sh", "-c", srvc->tunnel, NULL);
1016 + _exit(127);
1017 }
1018
1040 - close (a[0]);
1019 + close(a[0]);
1020
1021 imap->buf.sock.fd = a[1];
1022
1044 - imap_info( "ok\n" );
1023 + imap_info("ok\n");
1024 } else {
1046 - memset( &addr, 0, sizeof(addr) );
1047 - addr.sin_port = htons( srvc->port );
1025 + memset(&addr, 0, sizeof(addr));
1026 + addr.sin_port = htons(srvc->port);
1027 addr.sin_family = AF_INET;
1028
1050 - imap_info( "Resolving %s... ", srvc->host );
1051 - he = gethostbyname( srvc->host );
1029 + imap_info("Resolving %s... ", srvc->host);
1030 + he = gethostbyname(srvc->host);
1031 if (!he) {
1053 - perror( "gethostbyname" );
1032 + perror("gethostbyname");
1033 goto bail;
1034 }
1056 - imap_info( "ok\n" );
1035 + imap_info("ok\n");
1036
1037 addr.sin_addr.s_addr = *((int *) he->h_addr_list[0]);
1038
1060 - s = socket( PF_INET, SOCK_STREAM, 0 );
1039 + s = socket(PF_INET, SOCK_STREAM, 0);
1040
1062 - imap_info( "Connecting to %s:%hu... ", inet_ntoa( addr.sin_addr ), ntohs( addr.sin_port ) );
1063 - if (connect( s, (struct sockaddr *)&addr, sizeof(addr) )) {
1064 - close( s );
1065 - perror( "connect" );
1041 + imap_info("Connecting to %s:%hu... ", inet_ntoa(addr.sin_addr), ntohs(addr.sin_port));
1042 + if (connect(s, (struct sockaddr *)&addr, sizeof(addr))) {
1043 + close(s);
1044 + perror("connect");
1045 goto bail;
1046 }
1047
@@ -1073,28 +1052,28 @@ imap_open_store( imap_server_conf_t *srvc )
1052 close(s);
1053 goto bail;
1054 }
1076 - imap_info( "ok\n" );
1055 + imap_info("ok\n");
1056 }
1057
1058 /* read the greeting string */
1080 - if (buffer_gets( &imap->buf, &rsp )) {
1081 - fprintf( stderr, "IMAP error: no greeting response\n" );
1059 + if (buffer_gets(&imap->buf, &rsp)) {
1060 + fprintf(stderr, "IMAP error: no greeting response\n");
1061 goto bail;
1062 }
1084 - arg = next_arg( &rsp );
1085 - if (!arg || *arg != '*' || (arg = next_arg( &rsp )) == NULL) {
1086 - fprintf( stderr, "IMAP error: invalid greeting response\n" );
1063 + arg = next_arg(&rsp);
1064 + if (!arg || *arg != '*' || (arg = next_arg(&rsp)) == NULL) {
1065 + fprintf(stderr, "IMAP error: invalid greeting response\n");
1066 goto bail;
1067 }
1068 preauth = 0;
1090 - if (!strcmp( "PREAUTH", arg ))
1069 + if (!strcmp("PREAUTH", arg))
1070 preauth = 1;
1092 - else if (strcmp( "OK", arg ) != 0) {
1093 - fprintf( stderr, "IMAP error: unknown greeting response\n" );
1071 + else if (strcmp("OK", arg) != 0) {
1072 + fprintf(stderr, "IMAP error: unknown greeting response\n");
1073 goto bail;
1074 }
1096 - parse_response_code( ctx, NULL, rsp );
1097 - if (!imap->caps && imap_exec( ctx, NULL, "CAPABILITY" ) != RESP_OK)
1075 + parse_response_code(ctx, NULL, rsp);
1076 + if (!imap->caps && imap_exec(ctx, NULL, "CAPABILITY") != RESP_OK)
1077 goto bail;
1078
1079 if (!preauth) {
@@ -1110,38 +1089,38 @@ imap_open_store( imap_server_conf_t *srvc )
1089 goto bail;
1090 }
1091 #endif
1113 - imap_info ("Logging in...\n");
1092 + imap_info("Logging in...\n");
1093 if (!srvc->user) {
1115 - fprintf( stderr, "Skipping server %s, no user\n", srvc->host );
1094 + fprintf(stderr, "Skipping server %s, no user\n", srvc->host);
1095 goto bail;
1096 }
1097 if (!srvc->pass) {
1098 char prompt[80];
1120 - sprintf( prompt, "Password (%s@%s): ", srvc->user, srvc->host );
1121 - arg = getpass( prompt );
1099 + sprintf(prompt, "Password (%s@%s): ", srvc->user, srvc->host);
1100 + arg = getpass(prompt);
1101 if (!arg) {
1123 - perror( "getpass" );
1124 - exit( 1 );
1102 + perror("getpass");
1103 + exit(1);
1104 }
1105 if (!*arg) {
1127 - fprintf( stderr, "Skipping account %s@%s, no password\n", srvc->user, srvc->host );
1106 + fprintf(stderr, "Skipping account %s@%s, no password\n", srvc->user, srvc->host);
1107 goto bail;
1108 }
1109 /*
1110 * getpass() returns a pointer to a static buffer. make a copy
1111 * for long term storage.
1112 */
1134 - srvc->pass = xstrdup( arg );
1113 + srvc->pass = xstrdup(arg);
1114 }
1115 if (CAP(NOLOGIN)) {
1137 - fprintf( stderr, "Skipping account %s@%s, server forbids LOGIN\n", srvc->user, srvc->host );
1116 + fprintf(stderr, "Skipping account %s@%s, server forbids LOGIN\n", srvc->user, srvc->host);
1117 goto bail;
1118 }
1119 if (!imap->buf.sock.ssl)
1120 imap_warn( "*** IMAP Warning *** Password is being "
1121 "sent in the clear\n" );
1143 - if (imap_exec( ctx, NULL, "LOGIN \"%s\" \"%s\"", srvc->user, srvc->pass ) != RESP_OK) {
1144 - fprintf( stderr, "IMAP error: LOGIN failed\n" );
1122 + if (imap_exec(ctx, NULL, "LOGIN \"%s\" \"%s\"", srvc->user, srvc->pass) != RESP_OK) {
1123 + fprintf(stderr, "IMAP error: LOGIN failed\n");
1124 goto bail;
1125 }
1126 } /* !preauth */
@@ -1151,12 +1130,11 @@ imap_open_store( imap_server_conf_t *srvc )
1130 return (store_t *)ctx;
1131
1132 bail:
1154 - imap_close_store( &ctx->gen );
1133 + imap_close_store(&ctx->gen);
1134 return NULL;
1135 }
1136
1158 -static int
1159 -imap_make_flags( int flags, char *buf )
1137 +static int imap_make_flags(int flags, char *buf)
1138 {
1139 const char *s;
1140 unsigned i, d;
@@ -1175,8 +1153,7 @@ imap_make_flags( int flags, char *buf )
1153
1154 #define TUIDL 8
1155
1178 -static int
1179 -imap_store_msg( store_t *gctx, msg_data_t *data, int *uid )
1156 +static int imap_store_msg(store_t *gctx, msg_data_t *data, int *uid)
1157 {
1158 imap_store_t *ctx = (imap_store_t *)gctx;
1159 imap_t *imap = ctx->imap;
@@ -1187,7 +1164,7 @@ imap_store_msg( store_t *gctx, msg_data_t *data, int *uid )
1164 int start, sbreak = 0, ebreak = 0;
1165 char flagstr[128], tuid[TUIDL * 2 + 1];
1166
1190 - memset( &cb, 0, sizeof(cb) );
1167 + memset(&cb, 0, sizeof(cb));
1168
1169 fmap = data->data;
1170 len = data->len;
@@ -1203,18 +1180,18 @@ imap_store_msg( store_t *gctx, msg_data_t *data, int *uid )
1180 sbreak = ebreak = i - 2 + nocr;
1181 goto mktid;
1182 }
1206 - if (!memcmp( fmap + start, "X-TUID: ", 8 )) {
1183 + if (!memcmp(fmap + start, "X-TUID: ", 8)) {
1184 extra -= (ebreak = i) - (sbreak = start) + nocr;
1185 goto mktid;
1186 }
1187 goto nloop;
1188 }
1189 /* invalid message */
1213 - free( fmap );
1190 + free(fmap);
1191 return DRV_MSG_BAD;
1192 mktid:
1193 for (j = 0; j < TUIDL; j++)
1217 - sprintf( tuid + j * 2, "%02x", arc4_getbyte() );
1194 + sprintf(tuid + j * 2, "%02x", arc4_getbyte());
1195 extra += 8 + TUIDL * 2 + 2;
1196 }
1197 if (nocr)
@@ -1223,7 +1200,7 @@ imap_store_msg( store_t *gctx, msg_data_t *data, int *uid )
1200 extra++;
1201
1202 cb.dlen = len + extra;
1226 - buf = cb.data = xmalloc( cb.dlen );
1203 + buf = cb.data = xmalloc(cb.dlen);
1204 i = 0;
1205 if (!CAP(UIDPLUS) && uid) {
1206 if (nocr) {
@@ -1234,12 +1211,12 @@ imap_store_msg( store_t *gctx, msg_data_t *data, int *uid )
1211 } else
1212 *buf++ = fmap[i];
1213 } else {
1237 - memcpy( buf, fmap, sbreak );
1214 + memcpy(buf, fmap, sbreak);
1215 buf += sbreak;
1216 }
1240 - memcpy( buf, "X-TUID: ", 8 );
1217 + memcpy(buf, "X-TUID: ", 8);
1218 buf += 8;
1242 - memcpy( buf, tuid, TUIDL * 2 );
1219 + memcpy(buf, tuid, TUIDL * 2);
1220 buf += TUIDL * 2;
1221 *buf++ = '\r';
1222 *buf++ = '\n';
@@ -1253,13 +1230,13 @@ imap_store_msg( store_t *gctx, msg_data_t *data, int *uid )
1230 } else
1231 *buf++ = fmap[i];
1232 } else
1256 - memcpy( buf, fmap + i, len - i );
1233 + memcpy(buf, fmap + i, len - i);
1234
1258 - free( fmap );
1235 + free(fmap);
1236
1237 d = 0;
1238 if (data->flags) {
1262 - d = imap_make_flags( data->flags, flagstr );
1239 + d = imap_make_flags(data->flags, flagstr);
1240 flagstr[d++] = ' ';
1241 }
1242 flagstr[d] = 0;
@@ -1272,11 +1249,11 @@ imap_store_msg( store_t *gctx, msg_data_t *data, int *uid )
1249 imap->caps = imap->rcaps & ~(1 << LITERALPLUS);
1250 } else {
1251 box = gctx->name;
1275 - prefix = !strcmp( box, "INBOX" ) ? "" : ctx->prefix;
1252 + prefix = !strcmp(box, "INBOX") ? "" : ctx->prefix;
1253 cb.create = 0;
1254 }
1255 cb.ctx = uid;
1279 - ret = imap_exec_m( ctx, &cb, "APPEND \"%s%s\" %s", prefix, box, flagstr );
1256 + ret = imap_exec_m(ctx, &cb, "APPEND \"%s%s\" %s", prefix, box, flagstr);
1257 imap->caps = imap->rcaps;
1258 if (ret != DRV_OK)
1259 return ret;
@@ -1290,8 +1267,7 @@ imap_store_msg( store_t *gctx, msg_data_t *data, int *uid )
1267
1268 #define CHUNKSIZE 0x1000
1269
1293 -static int
1294 -read_message( FILE *f, msg_data_t *msg )
1270 +static int read_message(FILE *f, msg_data_t *msg)
1271 {
1272 struct strbuf buf;
1273
@@ -1308,8 +1284,7 @@ read_message( FILE *f, msg_data_t *msg )
1284 return msg->len;
1285 }
1286
1311 -static int
1312 -count_messages( msg_data_t *msg )
1287 +static int count_messages(msg_data_t *msg)
1288 {
1289 int count = 0;
1290 char *p = msg->data;
@@ -1319,7 +1294,7 @@ count_messages( msg_data_t *msg )
1294 count++;
1295 p += 5;
1296 }
1322 - p = strstr( p+5, "\nFrom ");
1297 + p = strstr(p+5, "\nFrom ");
1298 if (!p)
1299 break;
1300 p++;
@@ -1327,22 +1302,21 @@ count_messages( msg_data_t *msg )
1302 return count;
1303 }
1304
1330 -static int
1331 -split_msg( msg_data_t *all_msgs, msg_data_t *msg, int *ofs )
1305 +static int split_msg(msg_data_t *all_msgs, msg_data_t *msg, int *ofs)
1306 {
1307 char *p, *data;
1308
1335 - memset( msg, 0, sizeof *msg );
1309 + memset(msg, 0, sizeof *msg);
1310 if (*ofs >= all_msgs->len)
1311 return 0;
1312
1339 - data = &all_msgs->data[ *ofs ];
1313 + data = &all_msgs->data[*ofs];
1314 msg->len = all_msgs->len - *ofs;
1315
1316 if (msg->len < 5 || prefixcmp(data, "From "))
1317 return 0;
1318
1345 - p = strchr( data, '\n' );
1319 + p = strchr(data, '\n');
1320 if (p) {
1321 p = &p[1];
1322 msg->len -= p-data;
@@ -1350,7 +1324,7 @@ split_msg( msg_data_t *all_msgs, msg_data_t *msg, int *ofs )
1324 data = p;
1325 }
1326
1353 - p = strstr( data, "\nFrom " );
1327 + p = strstr(data, "\nFrom ");
1328 if (p)
1329 msg->len = &p[1] - data;
1330
@@ -1359,8 +1333,7 @@ split_msg( msg_data_t *all_msgs, msg_data_t *msg, int *ofs )
1333 return 1;
1334 }
1335
1362 -static imap_server_conf_t server =
1363 -{
1336 +static imap_server_conf_t server = {
1337 NULL, /* name */
1338 NULL, /* tunnel */
1339 NULL, /* host */
@@ -1373,12 +1346,11 @@ static imap_server_conf_t server =
1346
1347 static char *imap_folder;
1348
1376 -static int
1377 -git_imap_config(const char *key, const char *val, void *cb)
1349 +static int git_imap_config(const char *key, const char *val, void *cb)
1350 {
1351 char imap_key[] = "imap.";
1352
1381 - if (strncmp( key, imap_key, sizeof imap_key - 1 ))
1353 + if (strncmp(key, imap_key, sizeof imap_key - 1))
1354 return 0;
1355
1356 if (!val)
@@ -1386,9 +1358,9 @@ git_imap_config(const char *key, const char *val, void *cb)
1358
1359 key += sizeof imap_key - 1;
1360
1389 - if (!strcmp( "folder", key )) {
1390 - imap_folder = xstrdup( val );
1391 - } else if (!strcmp( "host", key )) {
1361 + if (!strcmp("folder", key)) {
1362 + imap_folder = xstrdup(val);
1363 + } else if (!strcmp("host", key)) {
1364 if (!prefixcmp(val, "imap:"))
1365 val += 5;
1366 else if (!prefixcmp(val, "imaps:")) {
@@ -1397,23 +1369,22 @@ git_imap_config(const char *key, const char *val, void *cb)
1369 }
1370 if (!prefixcmp(val, "//"))
1371 val += 2;
1400 - server.host = xstrdup( val );
1372 + server.host = xstrdup(val);
1373 }
1402 - else if (!strcmp( "user", key ))
1403 - server.user = xstrdup( val );
1404 - else if (!strcmp( "pass", key ))
1405 - server.pass = xstrdup( val );
1406 - else if (!strcmp( "port", key ))
1407 - server.port = git_config_int( key, val );
1408 - else if (!strcmp( "tunnel", key ))
1409 - server.tunnel = xstrdup( val );
1410 - else if (!strcmp( "sslverify", key ))
1411 - server.ssl_verify = git_config_bool( key, val );
1374 + else if (!strcmp("user", key))
1375 + server.user = xstrdup(val);
1376 + else if (!strcmp("pass", key))
1377 + server.pass = xstrdup(val);
1378 + else if (!strcmp("port", key))
1379 + server.port = git_config_int(key, val);
1380 + else if (!strcmp("tunnel", key))
1381 + server.tunnel = xstrdup(val);
1382 + else if (!strcmp("sslverify", key))
1383 + server.ssl_verify = git_config_bool(key, val);
1384 return 0;
1385 }
1386
1415 -int
1416 -main(int argc, char **argv)
1387 +int main(int argc, char **argv)
1388 {
1389 msg_data_t all_msgs, msg;
1390 store_t *ctx = NULL;
@@ -1433,50 +1404,50 @@ main(int argc, char **argv)
1404 server.port = server.use_ssl ? 993 : 143;
1405
1406 if (!imap_folder) {
1436 - fprintf( stderr, "no imap store specified\n" );
1407 + fprintf(stderr, "no imap store specified\n");
1408 return 1;
1409 }
1410 if (!server.host) {
1411 if (!server.tunnel) {
1441 - fprintf( stderr, "no imap host specified\n" );
1412 + fprintf(stderr, "no imap host specified\n");
1413 return 1;
1414 }
1415 server.host = "tunnel";
1416 }
1417
1418 /* read the messages */
1448 - if (!read_message( stdin, &all_msgs )) {
1419 + if (!read_message(stdin, &all_msgs)) {
1420 fprintf(stderr,"nothing to send\n");
1421 return 1;
1422 }
1423
1453 - total = count_messages( &all_msgs );
1424 + total = count_messages(&all_msgs);
1425 if (!total) {
1426 fprintf(stderr,"no messages to send\n");
1427 return 1;
1428 }
1429
1430 /* write it to the imap server */
1460 - ctx = imap_open_store( &server );
1431 + ctx = imap_open_store(&server);
1432 if (!ctx) {
1462 - fprintf( stderr,"failed to open store\n");
1433 + fprintf(stderr,"failed to open store\n");
1434 return 1;
1435 }
1436
1466 - fprintf( stderr, "sending %d message%s\n", total, (total!=1)?"s":"" );
1437 + fprintf(stderr, "sending %d message%s\n", total, (total!=1)?"s":"");
1438 ctx->name = imap_folder;
1439 while (1) {
1440 unsigned percent = n * 100 / total;
1470 - fprintf( stderr, "%4u%% (%d/%d) done\r", percent, n, total );
1471 - if (!split_msg( &all_msgs, &msg, &ofs ))
1441 + fprintf(stderr, "%4u%% (%d/%d) done\r", percent, n, total);
1442 + if (!split_msg(&all_msgs, &msg, &ofs))
1443 break;
1473 - r = imap_store_msg( ctx, &msg, &uid );
1444 + r = imap_store_msg(ctx, &msg, &uid);
1445 if (r != DRV_OK) break;
1446 n++;
1447 }
1477 - fprintf( stderr,"\n" );
1448 + fprintf(stderr, "\n");
1449
1479 - imap_close_store( ctx );
1450 + imap_close_store(ctx);
1451
1452 return 0;
1453 }