imap-send.c: more style fixes
The previous one sqeezed unnecessary whitespaces and joined function type and name in the definition split across lines. This patch further fixes many remaining style issues: - We are not particularly fond of typedef to hide the underlying struct definitions. - Asterisk comes next variable, i.e. "type *var", not "type * var" nor "type* var". - Casting to pointer to a type is "(type *)", not "(type*)". - An open brace comes on the same line as closing parenthesis of "if (...)" condition; "else" comes on the same line as closing brace of its corresponding "if (...) {". - Avoid single liner "if (...) <stmt>;"; they should be on two separate lines. Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
95c539081e
commit
9f1ad541f9
197
imap-send.c
197
imap-send.c
@ -27,70 +27,70 @@
|
|||||||
typedef void *SSL;
|
typedef void *SSL;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef struct store_conf {
|
struct store_conf {
|
||||||
char *name;
|
char *name;
|
||||||
const char *path; /* should this be here? its interpretation is driver-specific */
|
const char *path; /* should this be here? its interpretation is driver-specific */
|
||||||
char *map_inbox;
|
char *map_inbox;
|
||||||
char *trash;
|
char *trash;
|
||||||
unsigned max_size; /* off_t is overkill */
|
unsigned max_size; /* off_t is overkill */
|
||||||
unsigned trash_remote_new:1, trash_only_new:1;
|
unsigned trash_remote_new:1, trash_only_new:1;
|
||||||
} store_conf_t;
|
};
|
||||||
|
|
||||||
typedef struct string_list {
|
struct string_list {
|
||||||
struct string_list *next;
|
struct string_list *next;
|
||||||
char string[1];
|
char string[1];
|
||||||
} string_list_t;
|
};
|
||||||
|
|
||||||
typedef struct channel_conf {
|
struct channel_conf {
|
||||||
struct channel_conf *next;
|
struct channel_conf *next;
|
||||||
char *name;
|
char *name;
|
||||||
store_conf_t *master, *slave;
|
struct store_conf *master, *slave;
|
||||||
char *master_name, *slave_name;
|
char *master_name, *slave_name;
|
||||||
char *sync_state;
|
char *sync_state;
|
||||||
string_list_t *patterns;
|
struct string_list *patterns;
|
||||||
int mops, sops;
|
int mops, sops;
|
||||||
unsigned max_messages; /* for slave only */
|
unsigned max_messages; /* for slave only */
|
||||||
} channel_conf_t;
|
};
|
||||||
|
|
||||||
typedef struct group_conf {
|
struct group_conf {
|
||||||
struct group_conf *next;
|
struct group_conf *next;
|
||||||
char *name;
|
char *name;
|
||||||
string_list_t *channels;
|
struct string_list *channels;
|
||||||
} group_conf_t;
|
};
|
||||||
|
|
||||||
/* For message->status */
|
/* For message->status */
|
||||||
#define M_RECENT (1<<0) /* unsyncable flag; maildir_* depend on this being 1<<0 */
|
#define M_RECENT (1<<0) /* unsyncable flag; maildir_* depend on this being 1<<0 */
|
||||||
#define M_DEAD (1<<1) /* expunged */
|
#define M_DEAD (1<<1) /* expunged */
|
||||||
#define M_FLAGS (1<<2) /* flags fetched */
|
#define M_FLAGS (1<<2) /* flags fetched */
|
||||||
|
|
||||||
typedef struct message {
|
struct message {
|
||||||
struct message *next;
|
struct message *next;
|
||||||
/* string_list_t *keywords; */
|
/* struct string_list *keywords; */
|
||||||
size_t size; /* zero implies "not fetched" */
|
size_t size; /* zero implies "not fetched" */
|
||||||
int uid;
|
int uid;
|
||||||
unsigned char flags, status;
|
unsigned char flags, status;
|
||||||
} message_t;
|
};
|
||||||
|
|
||||||
typedef struct store {
|
struct store {
|
||||||
store_conf_t *conf; /* foreign */
|
struct store_conf *conf; /* foreign */
|
||||||
|
|
||||||
/* currently open mailbox */
|
/* currently open mailbox */
|
||||||
const char *name; /* foreign! maybe preset? */
|
const char *name; /* foreign! maybe preset? */
|
||||||
char *path; /* own */
|
char *path; /* own */
|
||||||
message_t *msgs; /* own */
|
struct message *msgs; /* own */
|
||||||
int uidvalidity;
|
int uidvalidity;
|
||||||
unsigned char opts; /* maybe preset? */
|
unsigned char opts; /* maybe preset? */
|
||||||
/* note that the following do _not_ reflect stats from msgs, but mailbox totals */
|
/* note that the following do _not_ reflect stats from msgs, but mailbox totals */
|
||||||
int count; /* # of messages */
|
int count; /* # of messages */
|
||||||
int recent; /* # of recent messages - don't trust this beyond the initial read */
|
int recent; /* # of recent messages - don't trust this beyond the initial read */
|
||||||
} store_t;
|
};
|
||||||
|
|
||||||
typedef struct {
|
struct msg_data {
|
||||||
char *data;
|
char *data;
|
||||||
int len;
|
int len;
|
||||||
unsigned char flags;
|
unsigned char flags;
|
||||||
unsigned int crlf:1;
|
unsigned int crlf:1;
|
||||||
} msg_data_t;
|
};
|
||||||
|
|
||||||
#define DRV_OK 0
|
#define DRV_OK 0
|
||||||
#define DRV_MSG_BAD -1
|
#define DRV_MSG_BAD -1
|
||||||
@ -104,7 +104,7 @@ static void imap_warn(const char *, ...);
|
|||||||
|
|
||||||
static char *next_arg(char **);
|
static char *next_arg(char **);
|
||||||
|
|
||||||
static void free_generic_messages(message_t *);
|
static void free_generic_messages(struct message *);
|
||||||
|
|
||||||
static int nfsnprintf(char *buf, int blen, const char *fmt, ...);
|
static int nfsnprintf(char *buf, int blen, const char *fmt, ...);
|
||||||
|
|
||||||
@ -125,7 +125,7 @@ static int nfvasprintf(char **strp, const char *fmt, va_list ap)
|
|||||||
static void arc4_init(void);
|
static void arc4_init(void);
|
||||||
static unsigned char arc4_getbyte(void);
|
static unsigned char arc4_getbyte(void);
|
||||||
|
|
||||||
typedef struct imap_server_conf {
|
struct imap_server_conf {
|
||||||
char *name;
|
char *name;
|
||||||
char *tunnel;
|
char *tunnel;
|
||||||
char *host;
|
char *host;
|
||||||
@ -134,58 +134,58 @@ typedef struct imap_server_conf {
|
|||||||
char *pass;
|
char *pass;
|
||||||
int use_ssl;
|
int use_ssl;
|
||||||
int ssl_verify;
|
int ssl_verify;
|
||||||
} imap_server_conf_t;
|
};
|
||||||
|
|
||||||
typedef struct imap_store_conf {
|
struct imap_store_conf {
|
||||||
store_conf_t gen;
|
struct store_conf gen;
|
||||||
imap_server_conf_t *server;
|
struct imap_server_conf *server;
|
||||||
unsigned use_namespace:1;
|
unsigned use_namespace:1;
|
||||||
} imap_store_conf_t;
|
};
|
||||||
|
|
||||||
#define NIL (void *)0x1
|
#define NIL (void *)0x1
|
||||||
#define LIST (void *)0x2
|
#define LIST (void *)0x2
|
||||||
|
|
||||||
typedef struct _list {
|
struct imap_list {
|
||||||
struct _list *next, *child;
|
struct imap_list *next, *child;
|
||||||
char *val;
|
char *val;
|
||||||
int len;
|
int len;
|
||||||
} list_t;
|
};
|
||||||
|
|
||||||
typedef struct {
|
struct imap_socket {
|
||||||
int fd;
|
int fd;
|
||||||
SSL *ssl;
|
SSL *ssl;
|
||||||
} Socket_t;
|
};
|
||||||
|
|
||||||
typedef struct {
|
struct imap_buffer {
|
||||||
Socket_t sock;
|
struct imap_socket sock;
|
||||||
int bytes;
|
int bytes;
|
||||||
int offset;
|
int offset;
|
||||||
char buf[1024];
|
char buf[1024];
|
||||||
} buffer_t;
|
};
|
||||||
|
|
||||||
struct imap_cmd;
|
struct imap_cmd;
|
||||||
|
|
||||||
typedef struct imap {
|
struct imap {
|
||||||
int uidnext; /* from SELECT responses */
|
int uidnext; /* from SELECT responses */
|
||||||
list_t *ns_personal, *ns_other, *ns_shared; /* NAMESPACE info */
|
struct imap_list *ns_personal, *ns_other, *ns_shared; /* NAMESPACE info */
|
||||||
unsigned caps, rcaps; /* CAPABILITY results */
|
unsigned caps, rcaps; /* CAPABILITY results */
|
||||||
/* command queue */
|
/* command queue */
|
||||||
int nexttag, num_in_progress, literal_pending;
|
int nexttag, num_in_progress, literal_pending;
|
||||||
struct imap_cmd *in_progress, **in_progress_append;
|
struct imap_cmd *in_progress, **in_progress_append;
|
||||||
buffer_t buf; /* this is BIG, so put it last */
|
struct imap_buffer buf; /* this is BIG, so put it last */
|
||||||
} imap_t;
|
};
|
||||||
|
|
||||||
typedef struct imap_store {
|
struct imap_store {
|
||||||
store_t gen;
|
struct store gen;
|
||||||
int uidvalidity;
|
int uidvalidity;
|
||||||
imap_t *imap;
|
struct imap *imap;
|
||||||
const char *prefix;
|
const char *prefix;
|
||||||
unsigned /*currentnc:1,*/ trashnc:1;
|
unsigned /*currentnc:1,*/ trashnc:1;
|
||||||
} imap_store_t;
|
};
|
||||||
|
|
||||||
struct imap_cmd_cb {
|
struct imap_cmd_cb {
|
||||||
int (*cont)(imap_store_t *ctx, struct imap_cmd *cmd, const char *prompt);
|
int (*cont)(struct imap_store *ctx, struct imap_cmd *cmd, const char *prompt);
|
||||||
void (*done)(imap_store_t *ctx, struct imap_cmd *cmd, int response);
|
void (*done)(struct imap_store *ctx, struct imap_cmd *cmd, int response);
|
||||||
void *ctx;
|
void *ctx;
|
||||||
char *data;
|
char *data;
|
||||||
int dlen;
|
int dlen;
|
||||||
@ -222,7 +222,7 @@ static const char *cap_list[] = {
|
|||||||
#define RESP_NO 1
|
#define RESP_NO 1
|
||||||
#define RESP_BAD 2
|
#define RESP_BAD 2
|
||||||
|
|
||||||
static int get_cmd_result(imap_store_t *ctx, struct imap_cmd *tcmd);
|
static int get_cmd_result(struct imap_store *ctx, struct imap_cmd *tcmd);
|
||||||
|
|
||||||
|
|
||||||
static const char *Flags[] = {
|
static const char *Flags[] = {
|
||||||
@ -240,7 +240,7 @@ static void ssl_socket_perror(const char *func)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void socket_perror(const char *func, Socket_t *sock, int ret)
|
static void socket_perror(const char *func, struct imap_socket *sock, int ret)
|
||||||
{
|
{
|
||||||
#ifndef NO_OPENSSL
|
#ifndef NO_OPENSSL
|
||||||
if (sock->ssl) {
|
if (sock->ssl) {
|
||||||
@ -265,7 +265,7 @@ static void socket_perror(const char *func, Socket_t *sock, int ret)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ssl_socket_connect(Socket_t *sock, int use_tls_only, int verify)
|
static int ssl_socket_connect(struct imap_socket *sock, int use_tls_only, int verify)
|
||||||
{
|
{
|
||||||
#ifdef NO_OPENSSL
|
#ifdef NO_OPENSSL
|
||||||
fprintf(stderr, "SSL requested but SSL support not compiled in\n");
|
fprintf(stderr, "SSL requested but SSL support not compiled in\n");
|
||||||
@ -317,7 +317,7 @@ static int ssl_socket_connect(Socket_t *sock, int use_tls_only, int verify)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static int socket_read(Socket_t *sock, char *buf, int len)
|
static int socket_read(struct imap_socket *sock, char *buf, int len)
|
||||||
{
|
{
|
||||||
ssize_t n;
|
ssize_t n;
|
||||||
#ifndef NO_OPENSSL
|
#ifndef NO_OPENSSL
|
||||||
@ -334,7 +334,7 @@ static int socket_read(Socket_t *sock, char *buf, int len)
|
|||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int socket_write(Socket_t *sock, const char *buf, int len)
|
static int socket_write(struct imap_socket *sock, const char *buf, int len)
|
||||||
{
|
{
|
||||||
int n;
|
int n;
|
||||||
#ifndef NO_OPENSSL
|
#ifndef NO_OPENSSL
|
||||||
@ -351,7 +351,7 @@ static int socket_write(Socket_t *sock, const char *buf, int len)
|
|||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void socket_shutdown(Socket_t *sock)
|
static void socket_shutdown(struct imap_socket *sock)
|
||||||
{
|
{
|
||||||
#ifndef NO_OPENSSL
|
#ifndef NO_OPENSSL
|
||||||
if (sock->ssl) {
|
if (sock->ssl) {
|
||||||
@ -363,7 +363,7 @@ static void socket_shutdown(Socket_t *sock)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* simple line buffering */
|
/* simple line buffering */
|
||||||
static int buffer_gets(buffer_t * b, char **s)
|
static int buffer_gets(struct imap_buffer *b, char **s)
|
||||||
{
|
{
|
||||||
int n;
|
int n;
|
||||||
int start = b->offset;
|
int start = b->offset;
|
||||||
@ -465,9 +465,9 @@ static char *next_arg(char **s)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void free_generic_messages(message_t *msgs)
|
static void free_generic_messages(struct message *msgs)
|
||||||
{
|
{
|
||||||
message_t *tmsg;
|
struct message *tmsg;
|
||||||
|
|
||||||
for (; msgs; msgs = tmsg) {
|
for (; msgs; msgs = tmsg) {
|
||||||
tmsg = msgs->next;
|
tmsg = msgs->next;
|
||||||
@ -533,11 +533,11 @@ static unsigned char arc4_getbyte(void)
|
|||||||
return rs.s[(si + sj) & 0xff];
|
return rs.s[(si + sj) & 0xff];
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct imap_cmd *v_issue_imap_cmd(imap_store_t *ctx,
|
static struct imap_cmd *v_issue_imap_cmd(struct imap_store *ctx,
|
||||||
struct imap_cmd_cb *cb,
|
struct imap_cmd_cb *cb,
|
||||||
const char *fmt, va_list ap)
|
const char *fmt, va_list ap)
|
||||||
{
|
{
|
||||||
imap_t *imap = ctx->imap;
|
struct imap *imap = ctx->imap;
|
||||||
struct imap_cmd *cmd;
|
struct imap_cmd *cmd;
|
||||||
int n, bufl;
|
int n, bufl;
|
||||||
char buf[1024];
|
char buf[1024];
|
||||||
@ -577,8 +577,7 @@ static struct imap_cmd *v_issue_imap_cmd(imap_store_t *ctx,
|
|||||||
n = socket_write(&imap->buf.sock, cmd->cb.data, cmd->cb.dlen);
|
n = socket_write(&imap->buf.sock, cmd->cb.data, cmd->cb.dlen);
|
||||||
free(cmd->cb.data);
|
free(cmd->cb.data);
|
||||||
if (n != cmd->cb.dlen ||
|
if (n != cmd->cb.dlen ||
|
||||||
(n = socket_write(&imap->buf.sock, "\r\n", 2)) != 2)
|
(n = socket_write(&imap->buf.sock, "\r\n", 2)) != 2) {
|
||||||
{
|
|
||||||
free(cmd->cmd);
|
free(cmd->cmd);
|
||||||
free(cmd);
|
free(cmd);
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -595,7 +594,7 @@ static struct imap_cmd *v_issue_imap_cmd(imap_store_t *ctx,
|
|||||||
return cmd;
|
return cmd;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct imap_cmd *issue_imap_cmd(imap_store_t *ctx,
|
static struct imap_cmd *issue_imap_cmd(struct imap_store *ctx,
|
||||||
struct imap_cmd_cb *cb,
|
struct imap_cmd_cb *cb,
|
||||||
const char *fmt, ...)
|
const char *fmt, ...)
|
||||||
{
|
{
|
||||||
@ -608,7 +607,7 @@ static struct imap_cmd *issue_imap_cmd(imap_store_t *ctx,
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int imap_exec(imap_store_t *ctx, struct imap_cmd_cb *cb,
|
static int imap_exec(struct imap_store *ctx, struct imap_cmd_cb *cb,
|
||||||
const char *fmt, ...)
|
const char *fmt, ...)
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
@ -623,7 +622,7 @@ static int imap_exec(imap_store_t *ctx, struct imap_cmd_cb *cb,
|
|||||||
return get_cmd_result(ctx, cmdp);
|
return get_cmd_result(ctx, cmdp);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int imap_exec_m(imap_store_t *ctx, struct imap_cmd_cb *cb,
|
static int imap_exec_m(struct imap_store *ctx, struct imap_cmd_cb *cb,
|
||||||
const char *fmt, ...)
|
const char *fmt, ...)
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
@ -642,19 +641,19 @@ static int imap_exec_m(imap_store_t *ctx, struct imap_cmd_cb *cb,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int is_atom(list_t *list)
|
static int is_atom(struct imap_list *list)
|
||||||
{
|
{
|
||||||
return list && list->val && list->val != NIL && list->val != LIST;
|
return list && list->val && list->val != NIL && list->val != LIST;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int is_list(list_t *list)
|
static int is_list(struct imap_list *list)
|
||||||
{
|
{
|
||||||
return list && list->val == LIST;
|
return list && list->val == LIST;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void free_list(list_t *list)
|
static void free_list(struct imap_list *list)
|
||||||
{
|
{
|
||||||
list_t *tmp;
|
struct imap_list *tmp;
|
||||||
|
|
||||||
for (; list; list = tmp) {
|
for (; list; list = tmp) {
|
||||||
tmp = list->next;
|
tmp = list->next;
|
||||||
@ -666,9 +665,9 @@ static void free_list(list_t *list)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int parse_imap_list_l(imap_t *imap, char **sp, list_t **curp, int level)
|
static int parse_imap_list_l(struct imap *imap, char **sp, struct imap_list **curp, int level)
|
||||||
{
|
{
|
||||||
list_t *cur;
|
struct imap_list *cur;
|
||||||
char *s = *sp, *p;
|
char *s = *sp, *p;
|
||||||
int n, bytes;
|
int n, bytes;
|
||||||
|
|
||||||
@ -737,12 +736,11 @@ static int parse_imap_list_l(imap_t *imap, char **sp, list_t **curp, int level)
|
|||||||
if (level && *s == ')')
|
if (level && *s == ')')
|
||||||
break;
|
break;
|
||||||
cur->len = s - p;
|
cur->len = s - p;
|
||||||
if (cur->len == 3 && !memcmp("NIL", p, 3)) {
|
if (cur->len == 3 && !memcmp("NIL", p, 3))
|
||||||
cur->val = NIL;
|
cur->val = NIL;
|
||||||
} else {
|
else
|
||||||
cur->val = xmemdupz(p, cur->len);
|
cur->val = xmemdupz(p, cur->len);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (!level)
|
if (!level)
|
||||||
break;
|
break;
|
||||||
@ -758,9 +756,9 @@ static int parse_imap_list_l(imap_t *imap, char **sp, list_t **curp, int level)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static list_t *parse_imap_list(imap_t *imap, char **sp)
|
static struct imap_list *parse_imap_list(struct imap *imap, char **sp)
|
||||||
{
|
{
|
||||||
list_t *head;
|
struct imap_list *head;
|
||||||
|
|
||||||
if (!parse_imap_list_l(imap, sp, &head, 0))
|
if (!parse_imap_list_l(imap, sp, &head, 0))
|
||||||
return head;
|
return head;
|
||||||
@ -768,12 +766,12 @@ static list_t *parse_imap_list(imap_t *imap, char **sp)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static list_t *parse_list(char **sp)
|
static struct imap_list *parse_list(char **sp)
|
||||||
{
|
{
|
||||||
return parse_imap_list(NULL, sp);
|
return parse_imap_list(NULL, sp);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void parse_capability(imap_t *imap, char *cmd)
|
static void parse_capability(struct imap *imap, char *cmd)
|
||||||
{
|
{
|
||||||
char *arg;
|
char *arg;
|
||||||
unsigned i;
|
unsigned i;
|
||||||
@ -786,10 +784,10 @@ static void parse_capability(imap_t *imap, char *cmd)
|
|||||||
imap->rcaps = imap->caps;
|
imap->rcaps = imap->caps;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int parse_response_code(imap_store_t *ctx, struct imap_cmd_cb *cb,
|
static int parse_response_code(struct imap_store *ctx, struct imap_cmd_cb *cb,
|
||||||
char *s)
|
char *s)
|
||||||
{
|
{
|
||||||
imap_t *imap = ctx->imap;
|
struct imap *imap = ctx->imap;
|
||||||
char *arg, *p;
|
char *arg, *p;
|
||||||
|
|
||||||
if (*s != '[')
|
if (*s != '[')
|
||||||
@ -821,8 +819,7 @@ static int parse_response_code(imap_store_t *ctx, struct imap_cmd_cb *cb,
|
|||||||
fprintf(stderr, "*** IMAP ALERT *** %s\n", p);
|
fprintf(stderr, "*** IMAP ALERT *** %s\n", p);
|
||||||
} else if (cb && cb->ctx && !strcmp("APPENDUID", arg)) {
|
} else if (cb && cb->ctx && !strcmp("APPENDUID", arg)) {
|
||||||
if (!(arg = next_arg(&s)) || !(ctx->gen.uidvalidity = atoi(arg)) ||
|
if (!(arg = next_arg(&s)) || !(ctx->gen.uidvalidity = atoi(arg)) ||
|
||||||
!(arg = next_arg(&s)) || !(*(int *)cb->ctx = atoi(arg)))
|
!(arg = next_arg(&s)) || !(*(int *)cb->ctx = atoi(arg))) {
|
||||||
{
|
|
||||||
fprintf(stderr, "IMAP error: malformed APPENDUID status\n");
|
fprintf(stderr, "IMAP error: malformed APPENDUID status\n");
|
||||||
return RESP_BAD;
|
return RESP_BAD;
|
||||||
}
|
}
|
||||||
@ -830,9 +827,9 @@ static int parse_response_code(imap_store_t *ctx, struct imap_cmd_cb *cb,
|
|||||||
return RESP_OK;
|
return RESP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int get_cmd_result(imap_store_t *ctx, struct imap_cmd *tcmd)
|
static int get_cmd_result(struct imap_store *ctx, struct imap_cmd *tcmd)
|
||||||
{
|
{
|
||||||
imap_t *imap = ctx->imap;
|
struct imap *imap = ctx->imap;
|
||||||
struct imap_cmd *cmdp, **pcmdp, *ncmdp;
|
struct imap_cmd *cmdp, **pcmdp, *ncmdp;
|
||||||
char *cmd, *arg, *arg1, *p;
|
char *cmd, *arg, *arg1, *p;
|
||||||
int n, resp, resp2, tag;
|
int n, resp, resp2, tag;
|
||||||
@ -957,9 +954,9 @@ static int get_cmd_result(imap_store_t *ctx, struct imap_cmd *tcmd)
|
|||||||
/* not reached */
|
/* not reached */
|
||||||
}
|
}
|
||||||
|
|
||||||
static void imap_close_server(imap_store_t *ictx)
|
static void imap_close_server(struct imap_store *ictx)
|
||||||
{
|
{
|
||||||
imap_t *imap = ictx->imap;
|
struct imap *imap = ictx->imap;
|
||||||
|
|
||||||
if (imap->buf.sock.fd != -1) {
|
if (imap->buf.sock.fd != -1) {
|
||||||
imap_exec(ictx, NULL, "LOGOUT");
|
imap_exec(ictx, NULL, "LOGOUT");
|
||||||
@ -971,17 +968,17 @@ static void imap_close_server(imap_store_t *ictx)
|
|||||||
free(imap);
|
free(imap);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void imap_close_store(store_t *ctx)
|
static void imap_close_store(struct store *ctx)
|
||||||
{
|
{
|
||||||
imap_close_server((imap_store_t *)ctx);
|
imap_close_server((struct imap_store *)ctx);
|
||||||
free_generic_messages(ctx->msgs);
|
free_generic_messages(ctx->msgs);
|
||||||
free(ctx);
|
free(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
static store_t *imap_open_store(imap_server_conf_t *srvc)
|
static struct store *imap_open_store(struct imap_server_conf *srvc)
|
||||||
{
|
{
|
||||||
imap_store_t *ctx;
|
struct imap_store *ctx;
|
||||||
imap_t *imap;
|
struct imap *imap;
|
||||||
char *arg, *rsp;
|
char *arg, *rsp;
|
||||||
struct hostent *he;
|
struct hostent *he;
|
||||||
struct sockaddr_in addr;
|
struct sockaddr_in addr;
|
||||||
@ -1127,7 +1124,7 @@ static store_t *imap_open_store(imap_server_conf_t *srvc)
|
|||||||
|
|
||||||
ctx->prefix = "";
|
ctx->prefix = "";
|
||||||
ctx->trashnc = 1;
|
ctx->trashnc = 1;
|
||||||
return (store_t *)ctx;
|
return (struct store *)ctx;
|
||||||
|
|
||||||
bail:
|
bail:
|
||||||
imap_close_store(&ctx->gen);
|
imap_close_store(&ctx->gen);
|
||||||
@ -1153,10 +1150,10 @@ static int imap_make_flags(int flags, char *buf)
|
|||||||
|
|
||||||
#define TUIDL 8
|
#define TUIDL 8
|
||||||
|
|
||||||
static int imap_store_msg(store_t *gctx, msg_data_t *data, int *uid)
|
static int imap_store_msg(struct store *gctx, struct msg_data *data, int *uid)
|
||||||
{
|
{
|
||||||
imap_store_t *ctx = (imap_store_t *)gctx;
|
struct imap_store *ctx = (struct imap_store *)gctx;
|
||||||
imap_t *imap = ctx->imap;
|
struct imap *imap = ctx->imap;
|
||||||
struct imap_cmd_cb cb;
|
struct imap_cmd_cb cb;
|
||||||
char *fmap, *buf;
|
char *fmap, *buf;
|
||||||
const char *prefix, *box;
|
const char *prefix, *box;
|
||||||
@ -1267,7 +1264,7 @@ static int imap_store_msg(store_t *gctx, msg_data_t *data, int *uid)
|
|||||||
|
|
||||||
#define CHUNKSIZE 0x1000
|
#define CHUNKSIZE 0x1000
|
||||||
|
|
||||||
static int read_message(FILE *f, msg_data_t *msg)
|
static int read_message(FILE *f, struct msg_data *msg)
|
||||||
{
|
{
|
||||||
struct strbuf buf;
|
struct strbuf buf;
|
||||||
|
|
||||||
@ -1284,7 +1281,7 @@ static int read_message(FILE *f, msg_data_t *msg)
|
|||||||
return msg->len;
|
return msg->len;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int count_messages(msg_data_t *msg)
|
static int count_messages(struct msg_data *msg)
|
||||||
{
|
{
|
||||||
int count = 0;
|
int count = 0;
|
||||||
char *p = msg->data;
|
char *p = msg->data;
|
||||||
@ -1302,7 +1299,7 @@ static int count_messages(msg_data_t *msg)
|
|||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int split_msg(msg_data_t *all_msgs, msg_data_t *msg, int *ofs)
|
static int split_msg(struct msg_data *all_msgs, struct msg_data *msg, int *ofs)
|
||||||
{
|
{
|
||||||
char *p, *data;
|
char *p, *data;
|
||||||
|
|
||||||
@ -1333,7 +1330,7 @@ static int split_msg(msg_data_t *all_msgs, msg_data_t *msg, int *ofs)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static imap_server_conf_t server = {
|
static struct imap_server_conf server = {
|
||||||
NULL, /* name */
|
NULL, /* name */
|
||||||
NULL, /* tunnel */
|
NULL, /* tunnel */
|
||||||
NULL, /* host */
|
NULL, /* host */
|
||||||
@ -1370,8 +1367,7 @@ static int git_imap_config(const char *key, const char *val, void *cb)
|
|||||||
if (!prefixcmp(val, "//"))
|
if (!prefixcmp(val, "//"))
|
||||||
val += 2;
|
val += 2;
|
||||||
server.host = xstrdup(val);
|
server.host = xstrdup(val);
|
||||||
}
|
} else if (!strcmp("user", key))
|
||||||
else if (!strcmp("user", key))
|
|
||||||
server.user = xstrdup(val);
|
server.user = xstrdup(val);
|
||||||
else if (!strcmp("pass", key))
|
else if (!strcmp("pass", key))
|
||||||
server.pass = xstrdup(val);
|
server.pass = xstrdup(val);
|
||||||
@ -1386,8 +1382,8 @@ static int git_imap_config(const char *key, const char *val, void *cb)
|
|||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
msg_data_t all_msgs, msg;
|
struct msg_data all_msgs, msg;
|
||||||
store_t *ctx = NULL;
|
struct store *ctx = NULL;
|
||||||
int uid = 0;
|
int uid = 0;
|
||||||
int ofs = 0;
|
int ofs = 0;
|
||||||
int r;
|
int r;
|
||||||
@ -1442,7 +1438,8 @@ int main(int argc, char **argv)
|
|||||||
if (!split_msg(&all_msgs, &msg, &ofs))
|
if (!split_msg(&all_msgs, &msg, &ofs))
|
||||||
break;
|
break;
|
||||||
r = imap_store_msg(ctx, &msg, &uid);
|
r = imap_store_msg(ctx, &msg, &uid);
|
||||||
if (r != DRV_OK) break;
|
if (r != DRV_OK)
|
||||||
|
break;
|
||||||
n++;
|
n++;
|
||||||
}
|
}
|
||||||
fprintf(stderr, "\n");
|
fprintf(stderr, "\n");
|
||||||
|
Loading…
Reference in New Issue
Block a user