summaryrefslogtreecommitdiffabout
path: root/kmicromail/libetpan/smtp/mailsmtp_helper.c
Unidiff
Diffstat (limited to 'kmicromail/libetpan/smtp/mailsmtp_helper.c') (more/less context) (ignore whitespace changes)
-rw-r--r--kmicromail/libetpan/smtp/mailsmtp_helper.c232
1 files changed, 232 insertions, 0 deletions
diff --git a/kmicromail/libetpan/smtp/mailsmtp_helper.c b/kmicromail/libetpan/smtp/mailsmtp_helper.c
new file mode 100644
index 0000000..32d6564
--- a/dev/null
+++ b/kmicromail/libetpan/smtp/mailsmtp_helper.c
@@ -0,0 +1,232 @@
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 "mailsmtp.h"
37#include <string.h>
38#include <stdlib.h>
39#include "mail.h"
40
41int mailsmtp_init(mailsmtp * session)
42{
43 int r;
44 session->esmtp = 0;
45 r = mailesmtp_ehlo(session);
46
47 if (r == MAILSMTP_NO_ERROR) {
48 // session->esmtp = TRUE;
49 return MAILSMTP_NO_ERROR;
50 }
51
52 r = mailsmtp_helo(session);
53 /* if (r == MAILSMTP_NO_ERROR) { */
54/* session->esmtp = FALSE; */
55/* return MAILSMTP_NO_ERROR; */
56/* } */
57
58 return r;
59}
60
61
62
63int mailesmtp_send(mailsmtp * session,
64 const char * from,
65 int return_full,
66 const char * envid,
67 clist * addresses,
68 const char * message, size_t size)
69{
70 int r;
71 clistiter * l;
72
73 if (!session->esmtp)
74 return mailsmtp_send(session, from, addresses, message, size);
75
76 r = mailesmtp_mail(session, from, return_full, envid);
77 if (r != MAILSMTP_NO_ERROR)
78 return r;
79
80 for(l = clist_begin(addresses) ; l != NULL; l = clist_next(l)) {
81 struct esmtp_address * addr;
82
83 addr = clist_content(l);
84
85 r = mailesmtp_rcpt(session, addr->address, addr->notify, addr->orcpt);
86 if (r != MAILSMTP_NO_ERROR)
87 return r;
88 }
89
90 r = mailsmtp_data(session);
91 if (r != MAILSMTP_NO_ERROR)
92 return r;
93
94 r = mailsmtp_data_message(session, message, size);
95 if (r != MAILSMTP_NO_ERROR)
96 return r;
97
98 return MAILSMTP_NO_ERROR;
99}
100
101int mailsmtp_send(mailsmtp * session,
102 const char * from,
103 clist * addresses,
104 const char * message, size_t size)
105{
106 int r;
107 clistiter * l;
108
109 r = mailsmtp_mail(session, from);
110 if (r != MAILSMTP_NO_ERROR)
111 return r;
112
113 for(l = clist_begin(addresses) ; l != NULL; l = clist_next(l)) {
114 struct esmtp_address * addr;
115
116 addr = clist_content(l);
117
118 r = mailsmtp_rcpt(session, addr->address);
119 if (r != MAILSMTP_NO_ERROR)
120 return r;
121 }
122
123 r = mailsmtp_data(session);
124 if (r != MAILSMTP_NO_ERROR)
125 return r;
126
127 r = mailsmtp_data_message(session, message, size);
128 if (r != MAILSMTP_NO_ERROR)
129 return r;
130
131 return MAILSMTP_NO_ERROR;
132}
133
134
135
136
137
138
139
140
141
142
143
144
145
146/* esmtp addresses and smtp addresses */
147
148static struct esmtp_address * esmtp_address_new(char * addr,
149 int notify, char * orcpt)
150{
151 struct esmtp_address * esmtpa;
152
153 esmtpa = malloc(sizeof(* esmtpa));
154 if (esmtpa == NULL)
155 return NULL;
156
157 esmtpa->address = strdup(addr);
158 if (esmtpa->address == NULL) {
159 free(esmtpa);
160 return NULL;
161 }
162
163 if (orcpt != NULL) {
164 esmtpa->orcpt = strdup(orcpt);
165 if (esmtpa->orcpt == NULL) {
166 free(esmtpa->address);
167 free(esmtpa);
168 return NULL;
169 }
170 }
171 else
172 esmtpa->orcpt = NULL;
173
174 esmtpa->notify = notify;
175
176 return esmtpa;
177}
178
179static void esmtp_address_free(struct esmtp_address * addr)
180{
181 if (addr->orcpt)
182 free(addr->orcpt);
183 if (addr->address)
184 free(addr->address);
185
186 free(addr);
187}
188
189clist * esmtp_address_list_new()
190{
191 return clist_new();
192}
193
194void esmtp_address_list_free(clist * l)
195{
196 clist_foreach(l, (clist_func) esmtp_address_free, NULL);
197 clist_free(l);
198}
199
200int esmtp_address_list_add(clist * list, char * address,
201 int notify, char * orcpt)
202{
203 struct esmtp_address * esmtpa;
204 int r;
205
206 esmtpa = esmtp_address_new(address, notify, orcpt);
207 if (esmtpa == NULL)
208 return -1;
209
210 r = clist_append(list, esmtpa);
211 if (r < 0) {
212 esmtp_address_free(esmtpa);
213 return -1;
214 }
215
216 return 0;
217}
218
219clist * smtp_address_list_new()
220{
221 return esmtp_address_list_new();
222}
223
224int smtp_address_list_add(clist * list, char * address)
225{
226 return esmtp_address_list_add(list, address, 0, NULL);
227}
228
229void smtp_address_list_free(clist * l)
230{
231 esmtp_address_list_free(l);
232}