2004-03-27 16:07:20 +00:00
|
|
|
/*
|
|
|
|
* mbsync - mailbox synchronizer
|
2002-12-28 15:31:20 +00:00
|
|
|
* Copyright (C) 2000-2002 Michael R. Elkins <me@mutt.org>
|
2011-04-10 17:25:46 +00:00
|
|
|
* Copyright (C) 2002-2006,2010-2012 Oswald Buddenhagen <ossi@users.sf.net>
|
2000-12-20 21:41:21 +00:00
|
|
|
*
|
|
|
|
* 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
|
2011-04-10 17:34:36 +00:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2002-10-30 02:31:20 +00:00
|
|
|
*
|
2004-03-27 16:07:20 +00:00
|
|
|
* As a special exception, mbsync may be linked with the OpenSSL library,
|
2002-10-30 02:31:20 +00:00
|
|
|
* despite that library's more restrictive license.
|
2000-12-20 21:41:21 +00:00
|
|
|
*/
|
|
|
|
|
2013-12-08 19:46:40 +00:00
|
|
|
#ifndef DRIVER_H
|
|
|
|
#define DRIVER_H
|
2003-05-07 00:06:37 +00:00
|
|
|
|
2013-12-08 19:46:40 +00:00
|
|
|
#include "config.h"
|
2004-03-27 16:07:20 +00:00
|
|
|
|
|
|
|
typedef struct driver driver_t;
|
|
|
|
|
|
|
|
typedef struct store_conf {
|
|
|
|
struct store_conf *next;
|
|
|
|
char *name;
|
|
|
|
driver_t *driver;
|
|
|
|
const char *path; /* should this be here? its interpretation is driver-specific */
|
2013-08-03 13:10:57 +00:00
|
|
|
const char *flat_delim;
|
2005-12-28 10:02:22 +00:00
|
|
|
const char *map_inbox;
|
|
|
|
const char *trash;
|
2004-03-27 16:07:20 +00:00
|
|
|
unsigned max_size; /* off_t is overkill */
|
2013-11-24 18:55:41 +00:00
|
|
|
char trash_remote_new, trash_only_new;
|
2004-03-27 16:07:20 +00:00
|
|
|
} store_conf_t;
|
|
|
|
|
|
|
|
/* For message->flags */
|
|
|
|
/* Keep the mailbox driver flag definitions in sync! */
|
|
|
|
/* The order is according to alphabetical maildir flag sort */
|
|
|
|
#define F_DRAFT (1<<0) /* Draft */
|
|
|
|
#define F_FLAGGED (1<<1) /* Flagged */
|
|
|
|
#define F_ANSWERED (1<<2) /* Replied */
|
|
|
|
#define F_SEEN (1<<3) /* Seen */
|
|
|
|
#define F_DELETED (1<<4) /* Trashed */
|
|
|
|
#define NUM_FLAGS 5
|
|
|
|
|
|
|
|
/* For message->status */
|
|
|
|
#define M_RECENT (1<<0) /* unsyncable flag; maildir_* depend on this being 1<<0 */
|
|
|
|
#define M_DEAD (1<<1) /* expunged */
|
|
|
|
#define M_FLAGS (1<<2) /* flags fetched */
|
|
|
|
|
2011-04-10 11:06:07 +00:00
|
|
|
#define TUIDL 12
|
|
|
|
|
2004-03-27 16:07:20 +00:00
|
|
|
typedef struct message {
|
|
|
|
struct message *next;
|
2006-01-30 10:26:04 +00:00
|
|
|
struct sync_rec *srec;
|
2004-03-27 16:07:20 +00:00
|
|
|
/* string_list_t *keywords; */
|
|
|
|
size_t size; /* zero implies "not fetched" */
|
|
|
|
int uid;
|
|
|
|
unsigned char flags, status;
|
2011-04-10 11:06:07 +00:00
|
|
|
char tuid[TUIDL];
|
2004-03-27 16:07:20 +00:00
|
|
|
} message_t;
|
|
|
|
|
|
|
|
/* For opts, both in store and driver_t->select() */
|
|
|
|
#define OPEN_OLD (1<<0)
|
|
|
|
#define OPEN_NEW (1<<1)
|
|
|
|
#define OPEN_FLAGS (1<<2)
|
|
|
|
#define OPEN_SIZE (1<<3)
|
|
|
|
#define OPEN_EXPUNGE (1<<5)
|
|
|
|
#define OPEN_SETFLAGS (1<<6)
|
|
|
|
#define OPEN_APPEND (1<<7)
|
2006-02-03 21:33:43 +00:00
|
|
|
#define OPEN_FIND (1<<8)
|
2004-03-27 16:07:20 +00:00
|
|
|
|
|
|
|
typedef struct store {
|
2006-03-20 19:38:20 +00:00
|
|
|
struct store *next;
|
2004-03-27 16:07:20 +00:00
|
|
|
store_conf_t *conf; /* foreign */
|
2006-03-20 19:27:38 +00:00
|
|
|
string_list_t *boxes; /* _list results - own */
|
2013-11-24 18:55:41 +00:00
|
|
|
char listed; /* was _list already run? */
|
2004-03-27 16:07:20 +00:00
|
|
|
|
2012-07-15 10:55:04 +00:00
|
|
|
void (*bad_callback)( void *aux );
|
|
|
|
void *bad_callback_aux;
|
|
|
|
|
2004-03-27 16:07:20 +00:00
|
|
|
/* currently open mailbox */
|
2012-08-18 11:58:14 +00:00
|
|
|
const char *orig_name; /* foreign! maybe preset? */
|
|
|
|
char *name; /* foreign! maybe preset? */
|
2004-03-27 16:07:20 +00:00
|
|
|
char *path; /* own */
|
|
|
|
message_t *msgs; /* own */
|
|
|
|
int uidvalidity;
|
2011-04-10 11:06:07 +00:00
|
|
|
int uidnext; /* from SELECT responses */
|
2006-02-03 21:33:43 +00:00
|
|
|
unsigned opts; /* maybe preset? */
|
2004-03-27 16:07:20 +00:00
|
|
|
/* note that the following do _not_ reflect stats from msgs, but mailbox totals */
|
|
|
|
int count; /* # of messages */
|
|
|
|
int recent; /* # of recent messages - don't trust this beyond the initial read */
|
|
|
|
} store_t;
|
|
|
|
|
2011-04-03 16:21:46 +00:00
|
|
|
/* When the callback is invoked (at most once per store), the store is fubar;
|
|
|
|
* call the driver's cancel_store() to dispose of it. */
|
2012-07-15 10:55:04 +00:00
|
|
|
static INLINE void
|
|
|
|
set_bad_callback( store_t *ctx, void (*cb)( void *aux ), void *aux )
|
|
|
|
{
|
|
|
|
ctx->bad_callback = cb;
|
|
|
|
ctx->bad_callback_aux = aux;
|
|
|
|
}
|
|
|
|
|
2004-03-27 16:07:20 +00:00
|
|
|
typedef struct {
|
|
|
|
char *data;
|
|
|
|
int len;
|
2013-07-28 13:55:13 +00:00
|
|
|
time_t date;
|
2004-03-27 16:07:20 +00:00
|
|
|
unsigned char flags;
|
|
|
|
} msg_data_t;
|
|
|
|
|
|
|
|
#define DRV_OK 0
|
2011-04-03 16:21:46 +00:00
|
|
|
/* Message went missing, or mailbox is full, etc. */
|
2006-03-21 20:03:21 +00:00
|
|
|
#define DRV_MSG_BAD 1
|
2011-04-03 16:21:46 +00:00
|
|
|
/* Something is wrong with the current mailbox - probably it is somehow inaccessible. */
|
2006-03-21 20:03:21 +00:00
|
|
|
#define DRV_BOX_BAD 2
|
2011-04-03 16:21:46 +00:00
|
|
|
/* The command has been cancel()ed or cancel_store()d. */
|
2012-07-15 10:55:04 +00:00
|
|
|
#define DRV_CANCELED 3
|
2006-03-21 20:03:21 +00:00
|
|
|
|
2011-04-03 16:21:46 +00:00
|
|
|
/* All memory belongs to the driver's user, unless stated otherwise. */
|
2004-03-27 16:07:20 +00:00
|
|
|
|
2010-02-06 09:34:41 +00:00
|
|
|
/*
|
|
|
|
This flag says that the driver CAN store messages with CRLFs,
|
|
|
|
not that it must. The lack of it OTOH implies that it CANNOT,
|
|
|
|
and as CRLF is the canonical format, we convert.
|
|
|
|
*/
|
2006-02-03 21:33:43 +00:00
|
|
|
#define DRV_CRLF 1
|
2013-12-08 15:37:20 +00:00
|
|
|
/*
|
|
|
|
This flag says that the driver will act upon (DFlags & VERBOSE).
|
|
|
|
*/
|
|
|
|
#define DRV_VERBOSE 2
|
2006-02-03 21:33:43 +00:00
|
|
|
|
2012-08-11 16:34:46 +00:00
|
|
|
#define LIST_PATH 1
|
|
|
|
#define LIST_INBOX 2
|
|
|
|
|
2004-03-27 16:07:20 +00:00
|
|
|
struct driver {
|
2006-02-03 21:33:43 +00:00
|
|
|
int flags;
|
2011-04-03 16:21:46 +00:00
|
|
|
|
|
|
|
/* Parse configuration. */
|
2012-09-15 09:46:42 +00:00
|
|
|
int (*parse_store)( conffile_t *cfg, store_conf_t **storep );
|
2011-04-03 16:21:46 +00:00
|
|
|
|
|
|
|
/* Close remaining server connections. All stores must be disowned first. */
|
2006-03-20 19:38:20 +00:00
|
|
|
void (*cleanup)( void );
|
2011-04-03 16:21:46 +00:00
|
|
|
|
|
|
|
/* Open a store with the given configuration. This may recycle existing
|
|
|
|
* server connections. Upon failure, a null store is passed to the callback. */
|
2013-12-08 15:37:20 +00:00
|
|
|
void (*open_store)( store_conf_t *conf, const char *label,
|
2006-03-21 20:03:21 +00:00
|
|
|
void (*cb)( store_t *ctx, void *aux ), void *aux );
|
2011-04-03 16:21:46 +00:00
|
|
|
|
|
|
|
/* Mark the store as available for recycling. Server connection may be kept alive. */
|
2006-03-20 19:38:20 +00:00
|
|
|
void (*disown_store)( store_t *ctx );
|
2011-04-03 16:21:46 +00:00
|
|
|
|
|
|
|
/* Discard the store after a bad_callback. The server connections will be closed.
|
|
|
|
* Pending commands will have their callbacks synchronously invoked with DRV_CANCELED. */
|
2006-03-20 19:38:20 +00:00
|
|
|
void (*cancel_store)( store_t *ctx );
|
2011-04-03 16:21:46 +00:00
|
|
|
|
2012-08-11 16:34:46 +00:00
|
|
|
/* List the mailboxes in this store. Flags are ORed LIST_* values. */
|
|
|
|
void (*list)( store_t *ctx, int flags,
|
2006-03-21 20:03:21 +00:00
|
|
|
void (*cb)( int sts, void *aux ), void *aux );
|
2011-04-03 16:21:46 +00:00
|
|
|
|
|
|
|
/* Invoked before select(), this informs the driver which operations (OP_*)
|
|
|
|
* will be performed on the mailbox. The driver may extend the set by implicitly
|
|
|
|
* needed or available operations. */
|
2006-01-29 11:22:45 +00:00
|
|
|
void (*prepare_opts)( store_t *ctx, int opts );
|
2011-04-03 16:21:46 +00:00
|
|
|
|
|
|
|
/* Open the mailbox ctx->name. Optionally create missing boxes.
|
|
|
|
* As a side effect, this should resolve ctx->path if applicable. */
|
2011-07-23 14:06:32 +00:00
|
|
|
void (*select)( store_t *ctx, int create,
|
|
|
|
void (*cb)( int sts, void *aux ), void *aux );
|
2011-04-03 16:21:46 +00:00
|
|
|
|
|
|
|
/* Load the message attributes needed to perform the requested operations.
|
|
|
|
* Consider only messages with UIDs between minuid and maxuid (inclusive)
|
|
|
|
* and those named in the excs array (smaller than minuid).
|
2011-04-10 11:06:07 +00:00
|
|
|
* The driver takes ownership of the excs array. Messages below newuid do not need
|
|
|
|
* to have the TUID populated even if OPEN_FIND is set. */
|
|
|
|
void (*load)( store_t *ctx, int minuid, int maxuid, int newuid, int *excs, int nexcs,
|
2011-07-23 14:06:32 +00:00
|
|
|
void (*cb)( int sts, void *aux ), void *aux );
|
2011-04-03 16:21:46 +00:00
|
|
|
|
|
|
|
/* Fetch the contents and flags of the given message from the current mailbox. */
|
2012-07-29 21:14:48 +00:00
|
|
|
void (*fetch_msg)( store_t *ctx, message_t *msg, msg_data_t *data,
|
|
|
|
void (*cb)( int sts, void *aux ), void *aux );
|
2011-04-03 16:21:46 +00:00
|
|
|
|
|
|
|
/* Store the given message to either the current mailbox or the trash folder.
|
2013-11-02 19:06:08 +00:00
|
|
|
* If the new copy's UID can be immediately determined, return it, otherwise -2. */
|
2012-07-29 21:14:48 +00:00
|
|
|
void (*store_msg)( store_t *ctx, msg_data_t *data, int to_trash,
|
|
|
|
void (*cb)( int sts, int uid, void *aux ), void *aux );
|
2011-04-03 16:21:46 +00:00
|
|
|
|
2011-04-10 11:06:07 +00:00
|
|
|
/* Index the messages which have newly appeared in the mailbox, including their
|
|
|
|
* temporary UID headers. This is needed if store_msg() does not guarantee returning
|
|
|
|
* a UID; otherwise the driver needs to implement only the OPEN_FIND flag. */
|
|
|
|
void (*find_new_msgs)( store_t *ctx,
|
|
|
|
void (*cb)( int sts, void *aux ), void *aux );
|
2011-04-03 16:21:46 +00:00
|
|
|
|
|
|
|
/* Add/remove the named flags to/from the given message. The message may be either
|
|
|
|
* a pre-fetched one (in which case the in-memory representation is updated),
|
|
|
|
* or it may be identifed by UID only. The operation may be delayed until commit()
|
|
|
|
* is called. */
|
2012-07-29 21:14:48 +00:00
|
|
|
void (*set_flags)( store_t *ctx, message_t *msg, int uid, int add, int del, /* msg can be null, therefore uid as a fallback */
|
|
|
|
void (*cb)( int sts, void *aux ), void *aux );
|
2011-04-03 16:21:46 +00:00
|
|
|
|
|
|
|
/* Move the given message from the current mailbox to the trash folder.
|
|
|
|
* This may expunge the original message immediately, but it needn't to. */
|
2012-07-29 21:14:48 +00:00
|
|
|
void (*trash_msg)( store_t *ctx, message_t *msg, /* This may expunge the original message immediately, but it needn't to */
|
|
|
|
void (*cb)( int sts, void *aux ), void *aux );
|
2011-04-03 16:21:46 +00:00
|
|
|
|
|
|
|
/* Expunge deleted messages from the current mailbox and close it.
|
|
|
|
* There is no need to explicitly close a mailbox if no expunge is needed. */
|
2012-07-29 21:14:48 +00:00
|
|
|
void (*close)( store_t *ctx, /* IMAP-style: expunge inclusive */
|
|
|
|
void (*cb)( int sts, void *aux ), void *aux );
|
2011-04-03 16:21:46 +00:00
|
|
|
|
|
|
|
/* Cancel queued commands which are not in flight yet; they will have their
|
|
|
|
* callbacks invoked with DRV_CANCELED. Afterwards, wait for the completion of
|
|
|
|
* the in-flight commands. If the store is canceled before this command completes,
|
|
|
|
* the callback will *not* be invoked. */
|
|
|
|
void (*cancel)( store_t *ctx,
|
2012-07-22 15:32:32 +00:00
|
|
|
void (*cb)( void *aux ), void *aux );
|
2011-04-03 16:21:46 +00:00
|
|
|
|
|
|
|
/* Commit any pending set_flags() commands. */
|
2006-03-21 20:03:21 +00:00
|
|
|
void (*commit)( store_t *ctx );
|
2000-12-20 21:41:21 +00:00
|
|
|
};
|
|
|
|
|
2004-03-27 16:07:20 +00:00
|
|
|
void free_generic_messages( message_t * );
|
2004-01-12 01:24:47 +00:00
|
|
|
|
2013-12-08 19:46:40 +00:00
|
|
|
void parse_generic_store( store_conf_t *store, conffile_t *cfg );
|
2004-03-27 16:07:20 +00:00
|
|
|
|
2006-03-20 18:36:49 +00:00
|
|
|
#define N_DRIVERS 2
|
|
|
|
extern driver_t *drivers[N_DRIVERS];
|
2004-03-27 16:07:20 +00:00
|
|
|
extern driver_t maildir_driver, imap_driver;
|
2013-12-08 19:46:40 +00:00
|
|
|
|
|
|
|
#endif
|