1 /* 2 * libEtPan! -- a mail stuff library 3 * 4 * Copyright (C) 2001, 2005 - DINH Viet Hoa 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 3. Neither the name of the libEtPan! project nor the names of its 16 * contributors may be used to endorse or promote products derived 17 * from this software without specific prior written permission. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND 20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE 23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 * SUCH DAMAGE. 30 */ 31 32 /* 33 * $Id: mailstorage_types.h,v 1.9 2006/05/22 13:39:40 hoa Exp $ 34 */ 35 36 #ifndef MAILSTORAGE_TYPES_H 37 38 #define MAILSTORAGE_TYPES_H 39 40 #include <libetpan/maildriver_types.h> 41 42 #ifdef __cplusplus 43 extern "C" { 44 #endif 45 46 struct mailstorage; 47 48 typedef struct mailstorage_driver mailstorage_driver; 49 50 51 /* 52 There is three kinds of identities : 53 - storage 54 - folders 55 - session 56 57 A storage (struct mailstorage) represents whether a server or 58 a main path, 59 60 A storage can be an IMAP server, the root path of a MH or a mbox file. 61 62 Folders (struct mailfolder) are the mailboxes we can 63 choose in the server or as sub-folder of the main path. 64 65 Folders for IMAP are the IMAP mailboxes, for MH this is one of the 66 folder of the MH storage, for mbox, there is only one folder, the 67 mbox file content; 68 69 A mail session (struct mailsession) is whether a connection to a server 70 or a path that is open. It is the abstraction lower folders and storage. 71 It allow us to send commands. 72 73 We have a session driver for mail session for each kind of storage. 74 75 From a session, we can get a message (struct mailmessage) to read. 76 We have a message driver for each kind of storage. 77 */ 78 79 /* 80 mailstorage_driver is the driver structure for mail storages 81 82 - name is the name of the driver 83 84 - connect() connects the storage to the remote access or to 85 the path in the local filesystem. 86 87 - get_folder() can have two kinds of behaviour. 88 Either it creates a new session and independant from the session 89 used by the storage and select the given mailbox or 90 it selects the given mailbox in the current session. 91 It depends on the efficiency of the mail driver. 92 93 - uninitialize() frees the data created with mailstorage constructor. 94 */ 95 96 struct mailstorage_driver { 97 char * sto_name; 98 int (* sto_connect)(struct mailstorage * storage); 99 int (* sto_get_folder_session)(struct mailstorage * storage, 100 char * pathname, mailsession ** result); 101 void (* sto_uninitialize)(struct mailstorage * storage); 102 }; 103 104 /* 105 mailstorage is the data structure for a storage 106 107 - id is the name of the storage, it can be NULL. 108 109 - data is the data specific to the driver. 110 This is the internal state of the storage. 111 112 - session is the session related to the storage. 113 114 - driver is the driver for the storage. 115 116 - shared_folders is the list of folders returned by the storage. 117 */ 118 119 struct mailstorage { 120 char * sto_id; 121 void * sto_data; 122 mailsession * sto_session; 123 mailstorage_driver * sto_driver; 124 clist * sto_shared_folders; /* list of (struct mailfolder *) */ 125 126 void * sto_user_data; 127 }; 128 129 130 131 /* 132 mailfolder is the data structure for a mailbox 133 134 - pathname is the path of the mailbox on the storage 135 136 - virtual_name is the folder identifier, it can be a path, 137 a name or NULL. 138 139 - storage is the storage to which the folder belongs to. 140 141 - session is the session related to the folder. It can be 142 different of the session of the storage. 143 144 - shared_session is != 0 if the session is the same as the 145 session of the storage. 146 147 - pos is the position of the folder in the "shared_folders" field 148 of the storage. 149 150 folders can be chained into a tree. 151 152 - parent is the parent of the folder. 153 154 - sibling_index is the index of the folder in the list of children 155 of the parent. 156 157 - children is the folder. 158 */ 159 160 struct mailfolder { 161 char * fld_pathname; 162 char * fld_virtual_name; 163 164 struct mailstorage * fld_storage; 165 166 mailsession * fld_session; 167 int fld_shared_session; 168 clistiter * fld_pos; 169 170 struct mailfolder * fld_parent; 171 unsigned int fld_sibling_index; 172 carray * fld_children; /* array of (struct mailfolder *) */ 173 174 void * fld_user_data; 175 }; 176 177 /* 178 this is the type of socket connection 179 */ 180 181 enum { 182 CONNECTION_TYPE_PLAIN, /* when the connection is plain text */ 183 CONNECTION_TYPE_STARTTLS, /* when the connection is first plain, 184 then, we want to switch to 185 TLS (secure connection) */ 186 CONNECTION_TYPE_TRY_STARTTLS, /* the connection is first plain, 187 then, we will try to switch to TLS */ 188 CONNECTION_TYPE_TLS, /* the connection is over TLS */ 189 CONNECTION_TYPE_COMMAND, /* the connection is over a shell command */ 190 CONNECTION_TYPE_COMMAND_STARTTLS, /* the connection is over a shell 191 command and STARTTLS will be used */ 192 CONNECTION_TYPE_COMMAND_TRY_STARTTLS, /* the connection is over 193 a shell command and STARTTLS will 194 be tried */ 195 CONNECTION_TYPE_COMMAND_TLS /* the connection is over a shell 196 command in TLS */ 197 }; 198 199 #ifdef __cplusplus 200 } 201 #endif 202 203 #endif 204