mirror of https://git.code.sf.net/p/isync/isync
Oswald Buddenhagen
11 years ago
18 changed files with 480 additions and 345 deletions
@ -0,0 +1,131 @@ |
|||||||
|
/*
|
||||||
|
* mbsync - mailbox synchronizer |
||||||
|
* Copyright (C) 2000-2002 Michael R. Elkins <me@mutt.org> |
||||||
|
* Copyright (C) 2002-2006,2010-2012 Oswald Buddenhagen <ossi@users.sf.net> |
||||||
|
* |
||||||
|
* This program is free software; you can redistribute it and/or modify |
||||||
|
* it under the terms of the GNU General Public License as published by |
||||||
|
* the Free Software Foundation; either version 2 of the License, or |
||||||
|
* (at your option) any later version. |
||||||
|
* |
||||||
|
* This program is distributed in the hope that it will be useful, |
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||||
|
* GNU General Public License for more details. |
||||||
|
* |
||||||
|
* You should have received a copy of the GNU General Public License |
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
* |
||||||
|
* As a special exception, mbsync may be linked with the OpenSSL library, |
||||||
|
* despite that library's more restrictive license. |
||||||
|
*/ |
||||||
|
|
||||||
|
#ifndef COMMON_H |
||||||
|
#define COMMON_H |
||||||
|
|
||||||
|
#include <autodefs.h> |
||||||
|
|
||||||
|
#include <sys/types.h> |
||||||
|
#include <stdarg.h> |
||||||
|
#include <stdio.h> |
||||||
|
|
||||||
|
#define as(ar) (sizeof(ar)/sizeof(ar[0])) |
||||||
|
|
||||||
|
#define __stringify(x) #x |
||||||
|
#define stringify(x) __stringify(x) |
||||||
|
|
||||||
|
#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4) |
||||||
|
# define ATTR_UNUSED __attribute__((unused)) |
||||||
|
# define ATTR_NORETURN __attribute__((noreturn)) |
||||||
|
# define ATTR_PRINTFLIKE(fmt,var) __attribute__((format(printf,fmt,var))) |
||||||
|
#else |
||||||
|
# define ATTR_UNUSED |
||||||
|
# define ATTR_NORETURN |
||||||
|
# define ATTR_PRINTFLIKE(fmt,var) |
||||||
|
#endif |
||||||
|
|
||||||
|
#ifdef __GNUC__ |
||||||
|
# define INLINE __inline__ |
||||||
|
#else |
||||||
|
# define INLINE |
||||||
|
#endif |
||||||
|
|
||||||
|
#define EXE "mbsync" |
||||||
|
|
||||||
|
/* main.c */ |
||||||
|
|
||||||
|
#define DEBUG 1 |
||||||
|
#define VERBOSE 2 |
||||||
|
#define XVERBOSE 4 |
||||||
|
#define QUIET 8 |
||||||
|
#define VERYQUIET 16 |
||||||
|
#define KEEPJOURNAL 32 |
||||||
|
#define ZERODELAY 64 |
||||||
|
#define CRASHDEBUG 128 |
||||||
|
|
||||||
|
extern int DFlags; |
||||||
|
extern int UseFSync; |
||||||
|
|
||||||
|
extern int Pid; |
||||||
|
extern char Hostname[256]; |
||||||
|
extern const char *Home; |
||||||
|
|
||||||
|
/* util.c */ |
||||||
|
|
||||||
|
void ATTR_PRINTFLIKE(1, 2) debug( const char *, ... ); |
||||||
|
void ATTR_PRINTFLIKE(1, 2) debugn( const char *, ... ); |
||||||
|
void ATTR_PRINTFLIKE(1, 2) info( const char *, ... ); |
||||||
|
void ATTR_PRINTFLIKE(1, 2) infon( const char *, ... ); |
||||||
|
void ATTR_PRINTFLIKE(1, 2) warn( const char *, ... ); |
||||||
|
void ATTR_PRINTFLIKE(1, 2) error( const char *, ... ); |
||||||
|
void ATTR_PRINTFLIKE(1, 2) sys_error( const char *, ... ); |
||||||
|
void flushn( void ); |
||||||
|
|
||||||
|
typedef struct string_list { |
||||||
|
struct string_list *next; |
||||||
|
char string[1]; |
||||||
|
} string_list_t; |
||||||
|
|
||||||
|
void add_string_list_n( string_list_t **list, const char *str, int len ); |
||||||
|
void add_string_list( string_list_t **list, const char *str ); |
||||||
|
void free_string_list( string_list_t *list ); |
||||||
|
|
||||||
|
#ifndef HAVE_MEMRCHR |
||||||
|
void *memrchr( const void *s, int c, size_t n ); |
||||||
|
#endif |
||||||
|
|
||||||
|
void *nfmalloc( size_t sz ); |
||||||
|
void *nfcalloc( size_t sz ); |
||||||
|
void *nfrealloc( void *mem, size_t sz ); |
||||||
|
char *nfstrdup( const char *str ); |
||||||
|
int nfvasprintf( char **str, const char *fmt, va_list va ); |
||||||
|
int ATTR_PRINTFLIKE(2, 3) nfasprintf( char **str, const char *fmt, ... ); |
||||||
|
int ATTR_PRINTFLIKE(3, 4) nfsnprintf( char *buf, int blen, const char *fmt, ... ); |
||||||
|
void ATTR_NORETURN oob( void ); |
||||||
|
|
||||||
|
char *expand_strdup( const char *s ); |
||||||
|
|
||||||
|
int map_name( const char *arg, char **result, int reserve, const char *in, const char *out ); |
||||||
|
|
||||||
|
void sort_ints( int *arr, int len ); |
||||||
|
|
||||||
|
void arc4_init( void ); |
||||||
|
unsigned char arc4_getbyte( void ); |
||||||
|
|
||||||
|
int bucketsForSize( int size ); |
||||||
|
|
||||||
|
#ifdef HAVE_SYS_POLL_H |
||||||
|
# include <sys/poll.h> |
||||||
|
#else |
||||||
|
# define POLLIN 1 |
||||||
|
# define POLLOUT 4 |
||||||
|
# define POLLERR 8 |
||||||
|
#endif |
||||||
|
|
||||||
|
void add_fd( int fd, void (*cb)( int events, void *aux ), void *aux ); |
||||||
|
void conf_fd( int fd, int and_events, int or_events ); |
||||||
|
void fake_fd( int fd, int events ); |
||||||
|
void del_fd( int fd ); |
||||||
|
void main_loop( void ); |
||||||
|
|
||||||
|
#endif |
@ -0,0 +1,45 @@ |
|||||||
|
/*
|
||||||
|
* mbsync - mailbox synchronizer |
||||||
|
* Copyright (C) 2000-2002 Michael R. Elkins <me@mutt.org> |
||||||
|
* Copyright (C) 2002-2006,2010-2012 Oswald Buddenhagen <ossi@users.sf.net> |
||||||
|
* |
||||||
|
* This program is free software; you can redistribute it and/or modify |
||||||
|
* it under the terms of the GNU General Public License as published by |
||||||
|
* the Free Software Foundation; either version 2 of the License, or |
||||||
|
* (at your option) any later version. |
||||||
|
* |
||||||
|
* This program is distributed in the hope that it will be useful, |
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||||
|
* GNU General Public License for more details. |
||||||
|
* |
||||||
|
* You should have received a copy of the GNU General Public License |
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
* |
||||||
|
* As a special exception, mbsync may be linked with the OpenSSL library, |
||||||
|
* despite that library's more restrictive license. |
||||||
|
*/ |
||||||
|
|
||||||
|
#ifndef CONFIG_H |
||||||
|
#define CONFIG_H |
||||||
|
|
||||||
|
#include "common.h" |
||||||
|
|
||||||
|
typedef struct conffile { |
||||||
|
const char *file; |
||||||
|
FILE *fp; |
||||||
|
char *buf; |
||||||
|
int bufl; |
||||||
|
int line; |
||||||
|
int err; |
||||||
|
char *cmd, *val, *rest; |
||||||
|
} conffile_t; |
||||||
|
|
||||||
|
int parse_bool( conffile_t *cfile ); |
||||||
|
int parse_int( conffile_t *cfile ); |
||||||
|
int parse_size( conffile_t *cfile ); |
||||||
|
int getcline( conffile_t *cfile ); |
||||||
|
int merge_ops( int cops, int ops[] ); |
||||||
|
int load_config( const char *filename, int pseudo ); |
||||||
|
|
||||||
|
#endif |
@ -0,0 +1,68 @@ |
|||||||
|
/*
|
||||||
|
* mbsync - mailbox synchronizer |
||||||
|
* Copyright (C) 2000-2002 Michael R. Elkins <me@mutt.org> |
||||||
|
* Copyright (C) 2002-2006,2010-2012 Oswald Buddenhagen <ossi@users.sf.net> |
||||||
|
* |
||||||
|
* This program is free software; you can redistribute it and/or modify |
||||||
|
* it under the terms of the GNU General Public License as published by |
||||||
|
* the Free Software Foundation; either version 2 of the License, or |
||||||
|
* (at your option) any later version. |
||||||
|
* |
||||||
|
* This program is distributed in the hope that it will be useful, |
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||||
|
* GNU General Public License for more details. |
||||||
|
* |
||||||
|
* You should have received a copy of the GNU General Public License |
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
* |
||||||
|
* As a special exception, mbsync may be linked with the OpenSSL library, |
||||||
|
* despite that library's more restrictive license. |
||||||
|
*/ |
||||||
|
|
||||||
|
#include "driver.h" |
||||||
|
|
||||||
|
#include <stdlib.h> |
||||||
|
#include <string.h> |
||||||
|
|
||||||
|
driver_t *drivers[N_DRIVERS] = { &maildir_driver, &imap_driver }; |
||||||
|
|
||||||
|
void |
||||||
|
free_generic_messages( message_t *msgs ) |
||||||
|
{ |
||||||
|
message_t *tmsg; |
||||||
|
|
||||||
|
for (; msgs; msgs = tmsg) { |
||||||
|
tmsg = msgs->next; |
||||||
|
free( msgs ); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
void |
||||||
|
parse_generic_store( store_conf_t *store, conffile_t *cfg ) |
||||||
|
{ |
||||||
|
if (!strcasecmp( "Trash", cfg->cmd )) { |
||||||
|
store->trash = nfstrdup( cfg->val ); |
||||||
|
} else if (!strcasecmp( "TrashRemoteNew", cfg->cmd )) { |
||||||
|
store->trash_remote_new = parse_bool( cfg ); |
||||||
|
} else if (!strcasecmp( "TrashNewOnly", cfg->cmd )) { |
||||||
|
store->trash_only_new = parse_bool( cfg ); |
||||||
|
} else if (!strcasecmp( "MaxSize", cfg->cmd )) { |
||||||
|
store->max_size = parse_size( cfg ); |
||||||
|
} else if (!strcasecmp( "MapInbox", cfg->cmd )) { |
||||||
|
store->map_inbox = nfstrdup( cfg->val ); |
||||||
|
} else if (!strcasecmp( "Flatten", cfg->cmd )) { |
||||||
|
const char *p; |
||||||
|
for (p = cfg->val; *p; p++) { |
||||||
|
if (*p == '/') { |
||||||
|
error( "%s:%d: flattened hierarchy delimiter cannot contain the canonical delimiter '/'\n", cfg->file, cfg->line ); |
||||||
|
cfg->err = 1; |
||||||
|
return; |
||||||
|
} |
||||||
|
} |
||||||
|
store->flat_delim = nfstrdup( cfg->val ); |
||||||
|
} else { |
||||||
|
error( "%s:%d: unknown keyword '%s'\n", cfg->file, cfg->line, cfg->cmd ); |
||||||
|
cfg->err = 1; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,118 @@ |
|||||||
|
/*
|
||||||
|
* mbsync - mailbox synchronizer |
||||||
|
* Copyright (C) 2000-2002 Michael R. Elkins <me@mutt.org> |
||||||
|
* Copyright (C) 2002-2006,2010-2012 Oswald Buddenhagen <ossi@users.sf.net> |
||||||
|
* |
||||||
|
* This program is free software; you can redistribute it and/or modify |
||||||
|
* it under the terms of the GNU General Public License as published by |
||||||
|
* the Free Software Foundation; either version 2 of the License, or |
||||||
|
* (at your option) any later version. |
||||||
|
* |
||||||
|
* This program is distributed in the hope that it will be useful, |
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||||
|
* GNU General Public License for more details. |
||||||
|
* |
||||||
|
* You should have received a copy of the GNU General Public License |
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
* |
||||||
|
* As a special exception, mbsync may be linked with the OpenSSL library, |
||||||
|
* despite that library's more restrictive license. |
||||||
|
*/ |
||||||
|
|
||||||
|
#ifndef SOCKET_H |
||||||
|
#define SOCKET_H |
||||||
|
|
||||||
|
#include "common.h" |
||||||
|
|
||||||
|
typedef struct ssl_st SSL; |
||||||
|
typedef struct ssl_ctx_st SSL_CTX; |
||||||
|
|
||||||
|
typedef struct server_conf { |
||||||
|
char *tunnel; |
||||||
|
char *host; |
||||||
|
int port; |
||||||
|
#ifdef HAVE_LIBSSL |
||||||
|
char *cert_file; |
||||||
|
char use_imaps; |
||||||
|
char use_sslv2, use_sslv3, use_tlsv1, use_tlsv11, use_tlsv12; |
||||||
|
|
||||||
|
/* these are actually variables and are leaked at the end */ |
||||||
|
char ssl_ctx_valid; |
||||||
|
unsigned num_trusted; |
||||||
|
SSL_CTX *SSLContext; |
||||||
|
#endif |
||||||
|
} server_conf_t; |
||||||
|
|
||||||
|
typedef struct buff_chunk { |
||||||
|
struct buff_chunk *next; |
||||||
|
char *data; |
||||||
|
int len; |
||||||
|
char buf[1]; |
||||||
|
} buff_chunk_t; |
||||||
|
|
||||||
|
typedef struct { |
||||||
|
/* connection */ |
||||||
|
int fd; |
||||||
|
int state; |
||||||
|
const server_conf_t *conf; /* needed during connect */ |
||||||
|
#ifdef HAVE_IPV6 |
||||||
|
struct addrinfo *addrs, *curr_addr; /* needed during connect */ |
||||||
|
#else |
||||||
|
char **curr_addr; /* needed during connect */ |
||||||
|
#endif |
||||||
|
char *name; |
||||||
|
#ifdef HAVE_LIBSSL |
||||||
|
SSL *ssl; |
||||||
|
int force_trusted; |
||||||
|
#endif |
||||||
|
|
||||||
|
void (*bad_callback)( void *aux ); /* async fail while sending or listening */ |
||||||
|
void (*read_callback)( void *aux ); /* data available for reading */ |
||||||
|
int (*write_callback)( void *aux ); /* all *queued* data was sent */ |
||||||
|
union { |
||||||
|
void (*connect)( int ok, void *aux ); |
||||||
|
void (*starttls)( int ok, void *aux ); |
||||||
|
} callbacks; |
||||||
|
void *callback_aux; |
||||||
|
|
||||||
|
/* writing */ |
||||||
|
buff_chunk_t *write_buf, **write_buf_append; /* buffer head & tail */ |
||||||
|
int write_offset; /* offset into buffer head */ |
||||||
|
|
||||||
|
/* reading */ |
||||||
|
int offset; /* start of filled bytes in buffer */ |
||||||
|
int bytes; /* number of filled bytes in buffer */ |
||||||
|
int scanoff; /* offset to continue scanning for newline at, relative to 'offset' */ |
||||||
|
char buf[100000]; |
||||||
|
} conn_t; |
||||||
|
|
||||||
|
/* call this before doing anything with the socket */ |
||||||
|
static INLINE void socket_init( conn_t *conn, |
||||||
|
const server_conf_t *conf, |
||||||
|
void (*bad_callback)( void *aux ), |
||||||
|
void (*read_callback)( void *aux ), |
||||||
|
int (*write_callback)( void *aux ), |
||||||
|
void *aux ) |
||||||
|
{ |
||||||
|
conn->conf = conf; |
||||||
|
conn->bad_callback = bad_callback; |
||||||
|
conn->read_callback = read_callback; |
||||||
|
conn->write_callback = write_callback; |
||||||
|
conn->callback_aux = aux; |
||||||
|
conn->fd = -1; |
||||||
|
conn->name = 0; |
||||||
|
conn->write_buf_append = &conn->write_buf; |
||||||
|
} |
||||||
|
void socket_connect( conn_t *conn, void (*cb)( int ok, void *aux ) ); |
||||||
|
void socket_start_tls(conn_t *conn, void (*cb)( int ok, void *aux ) ); |
||||||
|
void socket_close( conn_t *sock ); |
||||||
|
int socket_read( conn_t *sock, char *buf, int len ); /* never waits */ |
||||||
|
char *socket_read_line( conn_t *sock ); /* don't free return value; never waits */ |
||||||
|
typedef enum { KeepOwn = 0, GiveOwn } ownership_t; |
||||||
|
int socket_write( conn_t *sock, char *buf, int len, ownership_t takeOwn ); |
||||||
|
|
||||||
|
void cram( const char *challenge, const char *user, const char *pass, |
||||||
|
char **_final, int *_finallen ); |
||||||
|
|
||||||
|
#endif |
@ -0,0 +1,81 @@ |
|||||||
|
/*
|
||||||
|
* mbsync - mailbox synchronizer |
||||||
|
* Copyright (C) 2000-2002 Michael R. Elkins <me@mutt.org> |
||||||
|
* Copyright (C) 2002-2006,2010-2012 Oswald Buddenhagen <ossi@users.sf.net> |
||||||
|
* |
||||||
|
* This program is free software; you can redistribute it and/or modify |
||||||
|
* it under the terms of the GNU General Public License as published by |
||||||
|
* the Free Software Foundation; either version 2 of the License, or |
||||||
|
* (at your option) any later version. |
||||||
|
* |
||||||
|
* This program is distributed in the hope that it will be useful, |
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||||
|
* GNU General Public License for more details. |
||||||
|
* |
||||||
|
* You should have received a copy of the GNU General Public License |
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
* |
||||||
|
* As a special exception, mbsync may be linked with the OpenSSL library, |
||||||
|
* despite that library's more restrictive license. |
||||||
|
*/ |
||||||
|
|
||||||
|
#ifndef SYNC_H |
||||||
|
#define SYNC_H |
||||||
|
|
||||||
|
#include "driver.h" |
||||||
|
|
||||||
|
#define M 0 /* master */ |
||||||
|
#define S 1 /* slave */ |
||||||
|
|
||||||
|
#define OP_NEW (1<<0) |
||||||
|
#define OP_RENEW (1<<1) |
||||||
|
#define OP_DELETE (1<<2) |
||||||
|
#define OP_FLAGS (1<<3) |
||||||
|
#define OP_MASK_TYPE (OP_NEW|OP_RENEW|OP_DELETE|OP_FLAGS) /* asserted in the target ops */ |
||||||
|
#define OP_EXPUNGE (1<<4) |
||||||
|
#define OP_CREATE (1<<5) |
||||||
|
#define XOP_PUSH (1<<6) |
||||||
|
#define XOP_PULL (1<<7) |
||||||
|
#define XOP_MASK_DIR (XOP_PUSH|XOP_PULL) |
||||||
|
#define XOP_HAVE_TYPE (1<<8) |
||||||
|
#define XOP_HAVE_EXPUNGE (1<<9) |
||||||
|
#define XOP_HAVE_CREATE (1<<10) |
||||||
|
|
||||||
|
typedef struct channel_conf { |
||||||
|
struct channel_conf *next; |
||||||
|
const char *name; |
||||||
|
store_conf_t *stores[2]; |
||||||
|
const char *boxes[2]; |
||||||
|
char *sync_state; |
||||||
|
string_list_t *patterns; |
||||||
|
int ops[2]; |
||||||
|
unsigned max_messages; /* for slave only */ |
||||||
|
signed char expire_unread; |
||||||
|
char use_internal_date; |
||||||
|
} channel_conf_t; |
||||||
|
|
||||||
|
typedef struct group_conf { |
||||||
|
struct group_conf *next; |
||||||
|
const char *name; |
||||||
|
string_list_t *channels; |
||||||
|
} group_conf_t; |
||||||
|
|
||||||
|
extern channel_conf_t global_conf; |
||||||
|
extern channel_conf_t *channels; |
||||||
|
extern group_conf_t *groups; |
||||||
|
|
||||||
|
extern const char *str_ms[2], *str_hl[2]; |
||||||
|
|
||||||
|
#define SYNC_OK 0 /* assumed to be 0 */ |
||||||
|
#define SYNC_FAIL 1 |
||||||
|
#define SYNC_FAIL_ALL 2 |
||||||
|
#define SYNC_BAD(ms) (4<<(ms)) |
||||||
|
#define SYNC_NOGOOD 16 /* internal */ |
||||||
|
#define SYNC_CANCELED 32 /* internal */ |
||||||
|
|
||||||
|
/* All passed pointers must stay alive until cb is called. */ |
||||||
|
void sync_boxes( store_t *ctx[], const char *names[], channel_conf_t *chan, |
||||||
|
void (*cb)( int sts, void *aux ), void *aux ); |
||||||
|
|
||||||
|
#endif |
Loading…
Reference in new issue