Storage

Storage driver

#include <libetpan/libetpan.h>

typedef struct mailstorage_driver mailstorage_driver;

struct mailstorage_driver {
  char * sto_name;
  int (* sto_connect)(struct mailstorage * storage);
  int (* sto_get_folder_session)(struct mailstorage * storage,
      char * pathname, mailsession ** result);
  void (* sto_uninitialize)(struct mailstorage * storage);
};
        

This is the driver for a storage.

Storage

#include <libetpan/libetpan.h>

struct mailstorage {
  char * sto_id;
  void * sto_data;
  mailsession * sto_session;
  mailstorage_driver * sto_driver;
  clist * sto_shared_folders; /* list of (struct mailfolder *) */
  
  void * sto_user_data;
};
        

mailstorage_new and mailstorage_free

#include <libetpan/libetpan.h>

struct mailstorage * mailstorage_new(char * sto_id);

void mailstorage_free(struct mailstorage * storage);
        

mailstorage_new() initializes a storage structure with an identifier (sto_id) and with no driver.

mailstorage_free() free the memory used by a storage.

mailstorage_connect and mailstorage_disconnect

#include <libetpan/libetpan.h>

int mailstorage_connect(struct mailstorage * storage);

void mailstorage_disconnect(struct mailstorage * storage);
        

mailstorage_connect() connects the storage. This function can also be used to confirm that a storage connection is valid when the storage is already connected.

mailstorage_disconnect() disconnects the storage.

IMAP storage

int imap_mailstorage_init(struct mailstorage * storage,
    char * imap_servername, uint16_t imap_port,
    char * imap_command,
    int imap_connection_type, int imap_auth_type,
    char * imap_login, char * imap_password,
    int imap_cached, char * imap_cache_directory);
        

Example

Example 5-1. use of storage

int main(void)
{
  struct mailstorage * storage;
  int r;

  storage = mailstorage_new(NULL);
  
  imap_mailstorage_init(storage, "imap.my-servers.org", 0,
    NULL, CONNECTION_TYPE_TRY_STARTTLS, IMAP_AUTH_TYPE_PLAIN,
    "my-login", "my-password", 1, "/home/login/.libetpan/cache");

  r = mailstorage_connect(storage);
  if (r == MAIL_NO_ERROR) {
    mailstorage_disconnect(storage);
  }
  
  mailstorage_free(storage);
}