libEtPan! API
Prev | Chapter 5. Storages, folders, messages | Next

# 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.

- sto_name is the name of the driver.

- sto_connect() connects the storage to the remote access or to the path in the local filesystem.

- sto_get_folder_session() can have two kinds of behaviour. Either it creates a new session and independant from the session used by the storage and select the given mailbox or it selects the given mailbox in the current session. It depends on the efficiency of the mail access.

  XXX - in the future, this will be moved to the folder driver

- sto_uninitialize() frees the data created with mailstorage constructor.

## 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;
    };

- sto_id is an identifier for the storage. This can be NULL.

- sto_data is the internal data of the storage. This can only be changed by the driver.

- sto_session is the session used by the storage. The session can be used to send commands.

- sto_driver is the driver of the storage.

- sto_shared_folders is the list of folders that share the session with the storage. This is used internally.

- sto_user_data is a field for free use. The user can store any data in that field.

## 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);
    }

Prev | Home | Next
Error codes | Up | Folder