Diffstat (limited to 'kmicromail/libetpan/imap/mailimap_helper.c') (more/less context) (ignore whitespace changes)
-rw-r--r-- | kmicromail/libetpan/imap/mailimap_helper.c | 205 |
1 files changed, 205 insertions, 0 deletions
diff --git a/kmicromail/libetpan/imap/mailimap_helper.c b/kmicromail/libetpan/imap/mailimap_helper.c new file mode 100644 index 0000000..afc9098 --- a/dev/null +++ b/kmicromail/libetpan/imap/mailimap_helper.c | |||
@@ -0,0 +1,205 @@ | |||
1 | /* | ||
2 | * libEtPan! -- a mail stuff library | ||
3 | * | ||
4 | * Copyright (C) 2001, 2002 - 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 REGENTS 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 REGENTS 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$ | ||
34 | */ | ||
35 | |||
36 | #include "mailimap_helper.h" | ||
37 | |||
38 | #include <stdlib.h> | ||
39 | #include "mailimap.h" | ||
40 | |||
41 | int mailimap_fetch_rfc822(mailimap * session, | ||
42 | uint32_t msgid, char ** result) | ||
43 | { | ||
44 | int r; | ||
45 | clist * fetch_list; | ||
46 | struct mailimap_fetch_att * fetch_att; | ||
47 | struct mailimap_fetch_type * fetch_type; | ||
48 | struct mailimap_set * set; | ||
49 | struct mailimap_msg_att * msg_att; | ||
50 | struct mailimap_msg_att_item * item; | ||
51 | int res; | ||
52 | |||
53 | fetch_att = mailimap_fetch_att_new_rfc822(); | ||
54 | fetch_type = mailimap_fetch_type_new_fetch_att(fetch_att); | ||
55 | set = mailimap_set_new_single(msgid); | ||
56 | |||
57 | r = mailimap_fetch(session, set, fetch_type, &fetch_list); | ||
58 | |||
59 | mailimap_set_free(set); | ||
60 | mailimap_fetch_type_free(fetch_type); | ||
61 | |||
62 | if (r != MAILIMAP_NO_ERROR) { | ||
63 | res = r; | ||
64 | goto err; | ||
65 | } | ||
66 | |||
67 | if (clist_isempty(fetch_list)) { | ||
68 | res = MAILIMAP_ERROR_FETCH; | ||
69 | goto free; | ||
70 | } | ||
71 | |||
72 | msg_att = (struct mailimap_msg_att *) clist_begin(fetch_list)->data; | ||
73 | |||
74 | if (clist_isempty(msg_att->att_list)) { | ||
75 | res = MAILIMAP_ERROR_FETCH; | ||
76 | goto free; | ||
77 | } | ||
78 | |||
79 | item = (struct mailimap_msg_att_item *) clist_begin(msg_att->att_list)->data; | ||
80 | |||
81 | if (item->att_type != MAILIMAP_MSG_ATT_ITEM_STATIC) { | ||
82 | res = MAILIMAP_ERROR_FETCH; | ||
83 | goto free; | ||
84 | } | ||
85 | if (item->att_data.att_static->att_type != MAILIMAP_MSG_ATT_RFC822) { | ||
86 | res = MAILIMAP_ERROR_FETCH; | ||
87 | goto free; | ||
88 | } | ||
89 | |||
90 | * result = item->att_data.att_static->att_data.att_rfc822.att_content; | ||
91 | item->att_data.att_static->att_data.att_rfc822.att_content = NULL; | ||
92 | mailimap_fetch_list_free(fetch_list); | ||
93 | |||
94 | return MAILIMAP_NO_ERROR; | ||
95 | |||
96 | free: | ||
97 | mailimap_fetch_list_free(fetch_list); | ||
98 | err: | ||
99 | return res; | ||
100 | } | ||
101 | |||
102 | int mailimap_fetch_rfc822_header(mailimap * session, | ||
103 | uint32_t msgid, char ** result) | ||
104 | { | ||
105 | int r; | ||
106 | int res; | ||
107 | clist * fetch_list; | ||
108 | struct mailimap_fetch_att * fetch_att; | ||
109 | struct mailimap_fetch_type * fetch_type; | ||
110 | struct mailimap_set * set; | ||
111 | struct mailimap_msg_att * msg_att; | ||
112 | struct mailimap_msg_att_item * item; | ||
113 | |||
114 | fetch_att = mailimap_fetch_att_new_rfc822_header(); | ||
115 | fetch_type = mailimap_fetch_type_new_fetch_att(fetch_att); | ||
116 | set = mailimap_set_new_single(msgid); | ||
117 | |||
118 | r = mailimap_fetch(session, set, fetch_type, &fetch_list); | ||
119 | |||
120 | mailimap_set_free(set); | ||
121 | mailimap_fetch_type_free(fetch_type); | ||
122 | |||
123 | if (r != MAILIMAP_NO_ERROR) { | ||
124 | res = r; | ||
125 | goto err; | ||
126 | } | ||
127 | |||
128 | if (clist_isempty(fetch_list)) { | ||
129 | res = MAILIMAP_ERROR_FETCH; | ||
130 | goto free; | ||
131 | } | ||
132 | |||
133 | msg_att = (struct mailimap_msg_att *) clist_begin(fetch_list)->data; | ||
134 | |||
135 | if (clist_isempty(msg_att->att_list)) { | ||
136 | res = MAILIMAP_ERROR_FETCH; | ||
137 | goto free; | ||
138 | } | ||
139 | |||
140 | item = (struct mailimap_msg_att_item *) clist_begin(msg_att->att_list)->data; | ||
141 | |||
142 | if (item->att_type != MAILIMAP_MSG_ATT_ITEM_STATIC) { | ||
143 | res = MAILIMAP_ERROR_FETCH; | ||
144 | goto err; | ||
145 | } | ||
146 | |||
147 | if (item->att_data.att_static->att_type != MAILIMAP_MSG_ATT_RFC822_HEADER) { | ||
148 | res = MAILIMAP_ERROR_FETCH; | ||
149 | goto err; | ||
150 | } | ||
151 | |||
152 | * result = item->att_data.att_static->att_data.att_rfc822_header.att_content; | ||
153 | item->att_data.att_static->att_data.att_rfc822_header.att_content = NULL; | ||
154 | mailimap_fetch_list_free(fetch_list); | ||
155 | |||
156 | return MAILIMAP_NO_ERROR; | ||
157 | |||
158 | free: | ||
159 | mailimap_fetch_list_free(fetch_list); | ||
160 | err: | ||
161 | return res; | ||
162 | } | ||
163 | |||
164 | int mailimap_fetch_envelope(mailimap * session, | ||
165 | uint32_t first, uint32_t last, | ||
166 | clist ** result) | ||
167 | { | ||
168 | int r; | ||
169 | clist * fetch_list; | ||
170 | struct mailimap_fetch_att * fetch_att; | ||
171 | struct mailimap_fetch_type * fetch_type; | ||
172 | struct mailimap_set * set; | ||
173 | |||
174 | fetch_att = mailimap_fetch_att_new_envelope(); | ||
175 | fetch_type = mailimap_fetch_type_new_fetch_att(fetch_att); | ||
176 | set = mailimap_set_new_interval(first, last); | ||
177 | |||
178 | r = mailimap_fetch(session, set, fetch_type, &fetch_list); | ||
179 | |||
180 | mailimap_set_free(set); | ||
181 | mailimap_fetch_type_free(fetch_type); | ||
182 | |||
183 | if (r != MAILIMAP_NO_ERROR) | ||
184 | return r; | ||
185 | |||
186 | * result = fetch_list; | ||
187 | |||
188 | return MAILIMAP_NO_ERROR; | ||
189 | } | ||
190 | |||
191 | int mailimap_append_simple(mailimap * session, char * mailbox, | ||
192 | char * content, uint32_t size) | ||
193 | { | ||
194 | return mailimap_append(session, mailbox, NULL, NULL, content, size); | ||
195 | } | ||
196 | |||
197 | int mailimap_login_simple(mailimap * session, | ||
198 | char * userid, char * password) | ||
199 | { | ||
200 | if (session->imap_state == MAILIMAP_STATE_NON_AUTHENTICATED) | ||
201 | return mailimap_login(session, userid, password); | ||
202 | else | ||
203 | return MAILIMAP_NO_ERROR; | ||
204 | } | ||
205 | |||