X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=imap-send.c;h=a6a65680ee6daf062180d2580e83616cfff4cda4;hb=f73da29fa2be2f4bbda86e006b743b8121bdbf19;hp=52e2400b57118e7f9a27c85212e1c539d16add7c;hpb=3ffe0c245f290d55b32bed8b4ae04d00983df690;p=git.git diff --git a/imap-send.c b/imap-send.c index 52e2400b5..a6a65680e 100644 --- a/imap-send.c +++ b/imap-send.c @@ -93,7 +93,7 @@ typedef struct { char *data; int len; unsigned char flags; - unsigned char crlf:1; + unsigned int crlf:1; } msg_data_t; #define DRV_OK 0 @@ -110,7 +110,6 @@ static char *next_arg( char ** ); static void free_generic_messages( message_t * ); -static int nfvasprintf( char **str, const char *fmt, va_list va ); static int nfsnprintf( char *buf, int blen, const char *fmt, ... ); @@ -242,7 +241,7 @@ socket_read( Socket_t *sock, char *buf, int len ) } static int -socket_write( Socket_t *sock, char *buf, int len ) +socket_write( Socket_t *sock, const char *buf, int len ) { int n = write( sock->fd, buf, len ); if (n != len) { @@ -273,7 +272,7 @@ buffer_gets( buffer_t * b, char **s ) n = b->bytes - start; if (n) - memcpy( b->buf, b->buf + start, n ); + memmove(b->buf, b->buf + start, n); b->offset -= start; b->bytes = n; start = 0; @@ -371,21 +370,6 @@ free_generic_messages( message_t *msgs ) } } -static int -git_vasprintf( char **strp, const char *fmt, va_list ap ) -{ - int len; - char tmp[1024]; - - if ((len = vsnprintf( tmp, sizeof(tmp), fmt, ap )) < 0 || !(*strp = xmalloc( len + 1 ))) - return -1; - if (len >= (int)sizeof(tmp)) - vsprintf( *strp, fmt, ap ); - else - memcpy( *strp, tmp, len + 1 ); - return len; -} - static int nfsnprintf( char *buf, int blen, const char *fmt, ... ) { @@ -399,15 +383,6 @@ nfsnprintf( char *buf, int blen, const char *fmt, ... ) return ret; } -static int -nfvasprintf( char **str, const char *fmt, va_list va ) -{ - int ret = git_vasprintf( str, fmt, va ); - if (ret < 0) - die( "Fatal: Out of memory\n"); - return ret; -} - static struct { unsigned char i, j, s[256]; } rs; @@ -924,6 +899,7 @@ imap_open_store( imap_server_conf_t *srvc ) struct hostent *he; struct sockaddr_in addr; int s, a[2], preauth; + pid_t pid; ctx = xcalloc( sizeof(*ctx), 1 ); @@ -941,7 +917,10 @@ imap_open_store( imap_server_conf_t *srvc ) exit( 1 ); } - if (fork() == 0) { + pid = fork(); + if (pid < 0) + _exit( 127 ); + if (!pid) { if (dup2( a[0], 0 ) == -1 || dup2( a[0], 1 ) == -1) _exit( 127 ); close( a[0] ); @@ -1028,7 +1007,7 @@ imap_open_store( imap_server_conf_t *srvc ) * getpass() returns a pointer to a static buffer. make a copy * for long term storage. */ - srvc->pass = strdup( arg ); + srvc->pass = xstrdup( arg ); } if (CAP(NOLOGIN)) { fprintf( stderr, "Skipping account %s@%s, server forbids LOGIN\n", srvc->user, srvc->host ); @@ -1247,6 +1226,14 @@ split_msg( msg_data_t *all_msgs, msg_data_t *msg, int *ofs ) if (msg->len < 5 || strncmp( data, "From ", 5 )) return 0; + p = strchr( data, '\n' ); + if (p) { + p = &p[1]; + msg->len -= p-data; + *ofs += p-data; + data = p; + } + p = strstr( data, "\nFrom " ); if (p) msg->len = &p[1] - data; @@ -1284,7 +1271,7 @@ git_imap_config(const char *key, const char *val) key += sizeof imap_key - 1; if (!strcmp( "folder", key )) { - imap_folder = strdup( val ); + imap_folder = xstrdup( val ); } else if (!strcmp( "host", key )) { { if (!strncmp( "imap:", val, 5 )) @@ -1294,16 +1281,16 @@ git_imap_config(const char *key, const char *val) } if (!strncmp( "//", val, 2 )) val += 2; - server.host = strdup( val ); + server.host = xstrdup( val ); } else if (!strcmp( "user", key )) - server.user = strdup( val ); + server.user = xstrdup( val ); else if (!strcmp( "pass", key )) - server.pass = strdup( val ); + server.pass = xstrdup( val ); else if (!strcmp( "port", key )) server.port = git_config_int( key, val ); else if (!strcmp( "tunnel", key )) - server.tunnel = strdup( val ); + server.tunnel = xstrdup( val ); return 0; }