1 /* $Id$ */
2 /* Copyright (c) 2011-2012 Pierre Pronchery <khorben@defora.org> */
3 /* This file is part of DeforaOS Desktop Mailer */
4 /* This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, version 3 of the License.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program.  If not, see <http://www.gnu.org/licenses/>. */
15 
16 
17 
18 #ifndef DESKTOP_MAILER_ACCOUNT_H
19 # define DESKTOP_MAILER_ACCOUNT_H
20 
21 # include <openssl/ssl.h>
22 # include "folder.h"
23 # include "message.h"
24 
25 
26 /* Account */
27 /* types */
28 typedef struct _Account Account;
29 
30 /* AccountIdentity */
31 typedef struct _AccountIdentity
32 {
33 	char * from;
34 	char * email;
35 	char * signature;
36 } AccountIdentity;
37 
38 
39 /* AccountConfig */
40 typedef enum _AccountConfigType
41 {
42 	ACT_NONE = 0,
43 	/* values */
44 	ACT_STRING,
45 	ACT_PASSWORD,
46 	ACT_FILE,
47 	ACT_UINT16,
48 	ACT_BOOLEAN,
49 	/* layout */
50 	ACT_SEPARATOR
51 } AccountConfigType;
52 
53 typedef struct _AccountConfig
54 {
55 	char const * name;
56 	char const * title;
57 	AccountConfigType type;
58 	void * value;
59 } AccountConfig;
60 
61 
62 /* AccountStatus */
63 typedef enum _AccountStatus
64 {
65 	AS_CONNECTING = 0,
66 	AS_CONNECTED,
67 	AS_DISCONNECTED,
68 	AS_AUTHENTICATED,
69 	AS_IDLE
70 } AccountStatus;
71 
72 
73 /* AccountEvent */
74 typedef enum _AccountEventType
75 {
76 	AET_STARTED = 0,
77 	AET_STOPPED,
78 	AET_STATUS
79 } AccountEventType;
80 
81 typedef union _AccountEvent
82 {
83 	AccountEventType type;
84 
85 	/* AET_STATUS */
86 	struct
87 	{
88 		AccountEventType type;
89 		AccountStatus status;
90 		char const * message;
91 	} status;
92 } AccountEvent;
93 
94 
95 /* AccountPlugin */
96 typedef struct _AccountPluginHelper
97 {
98 	Account * account;
99 	/* accessors */
100 	SSL_CTX * (*get_ssl_context)(Account * account);
101 	/* useful */
102 	int (*error)(Account * account, char const * message, int ret);
103 	void (*event)(Account * account, AccountEvent * event);
104 	/* authentication */
105 	char * (*authenticate)(Account * account, char const * message);
106 	int (*confirm)(Account * account, char const * message);
107 	/* folders */
108 	Folder * (*folder_new)(Account * account, AccountFolder * folder,
109 			Folder * parent, FolderType type, char const * name);
110 	void (*folder_delete)(Folder * folder);
111 	/* messages */
112 	Message * (*message_new)(Account * account, Folder * folder,
113 			AccountMessage * message);
114 	void (*message_delete)(Message * message);
115 	void (*message_set_flag)(MailerMessage * message,
116 			MailerMessageFlag flag);
117 	int (*message_set_header)(Message * message, char const * header);
118 	int (*message_set_body)(Message * message, char const * buf, size_t cnt,
119 			int append);
120 } AccountPluginHelper;
121 
122 typedef struct _AccountPlugin AccountPlugin;
123 
124 typedef const struct _AccountPluginDefinition
125 {
126 	char const * type;
127 	char const * name;
128 	char const * icon;
129 	char const * description;
130 	AccountConfig const * config;
131 	AccountPlugin * (*init)(AccountPluginHelper * helper);
132 	int (*destroy)(AccountPlugin * plugin);
133 	AccountConfig * (*get_config)(AccountPlugin * plugin);
134 	char * (*get_source)(AccountPlugin * plugin, AccountFolder * folder,
135 			AccountMessage * message);
136 	int (*start)(AccountPlugin * plugin);
137 	void (*stop)(AccountPlugin * plugin);
138 	int (*refresh)(AccountPlugin * plugin, AccountFolder * folder,
139 			AccountMessage * message);
140 } AccountPluginDefinition;
141 
142 #endif /* !DESKTOP_MAILER_ACCOUNT_H */
143