Diffstat (limited to 'noncore/net/mail/libmailwrapper/smtpwrapper.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/net/mail/libmailwrapper/smtpwrapper.cpp | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/noncore/net/mail/libmailwrapper/smtpwrapper.cpp b/noncore/net/mail/libmailwrapper/smtpwrapper.cpp index d7a005e..63acfd5 100644 --- a/noncore/net/mail/libmailwrapper/smtpwrapper.cpp +++ b/noncore/net/mail/libmailwrapper/smtpwrapper.cpp | |||
@@ -104,125 +104,152 @@ mailimf_address_list *SMTPwrapper::parseAddresses(const QString&addr ) { | |||
104 | unsigned int startpos = 0; | 104 | unsigned int startpos = 0; |
105 | QStringList list; | 105 | QStringList list; |
106 | QString s; | 106 | QString s; |
107 | unsigned int i = 0; | 107 | unsigned int i = 0; |
108 | for (; i < addr.length();++i) { | 108 | for (; i < addr.length();++i) { |
109 | switch (addr[i]) { | 109 | switch (addr[i]) { |
110 | case '\"': | 110 | case '\"': |
111 | literal_open = !literal_open; | 111 | literal_open = !literal_open; |
112 | break; | 112 | break; |
113 | case ',': | 113 | case ',': |
114 | if (!literal_open) { | 114 | if (!literal_open) { |
115 | s = addr.mid(startpos,i-startpos); | 115 | s = addr.mid(startpos,i-startpos); |
116 | if (!s.isEmpty()) { | 116 | if (!s.isEmpty()) { |
117 | list.append(s); | 117 | list.append(s); |
118 | qDebug("Appended %s",s.latin1()); | 118 | qDebug("Appended %s",s.latin1()); |
119 | } | 119 | } |
120 | // !!!! this is a MUST BE! | 120 | // !!!! this is a MUST BE! |
121 | startpos = ++i; | 121 | startpos = ++i; |
122 | } | 122 | } |
123 | break; | 123 | break; |
124 | default: | 124 | default: |
125 | break; | 125 | break; |
126 | } | 126 | } |
127 | } | 127 | } |
128 | s = addr.mid(startpos,i-startpos); | 128 | s = addr.mid(startpos,i-startpos); |
129 | if (!s.isEmpty()) { | 129 | if (!s.isEmpty()) { |
130 | list.append(s); | 130 | list.append(s); |
131 | qDebug("Appended %s",s.latin1()); | 131 | qDebug("Appended %s",s.latin1()); |
132 | } | 132 | } |
133 | QStringList::Iterator it; | 133 | QStringList::Iterator it; |
134 | for ( it = list.begin(); it != list.end(); it++ ) { | 134 | for ( it = list.begin(); it != list.end(); it++ ) { |
135 | int err = mailimf_address_list_add_parse( addresses, (char*)(*it).latin1() ); | 135 | int err = mailimf_address_list_add_parse( addresses, (char*)(*it).latin1() ); |
136 | if ( err != MAILIMF_NO_ERROR ) { | 136 | if ( err != MAILIMF_NO_ERROR ) { |
137 | qDebug( "Error parsing" ); | 137 | qDebug( "Error parsing" ); |
138 | qDebug( *it ); | 138 | qDebug( *it ); |
139 | } else { | 139 | } else { |
140 | qDebug( "Parse success! %s",(*it).latin1()); | 140 | qDebug( "Parse success! %s",(*it).latin1()); |
141 | } | 141 | } |
142 | } | 142 | } |
143 | return addresses; | 143 | return addresses; |
144 | } | 144 | } |
145 | 145 | ||
146 | mailimf_fields *SMTPwrapper::createImfFields(const Mail&mail ) { | 146 | mailimf_fields *SMTPwrapper::createImfFields(const Mail&mail ) { |
147 | mailimf_fields *fields; | 147 | mailimf_fields *fields; |
148 | mailimf_field *xmailer; | 148 | mailimf_field *xmailer; |
149 | mailimf_mailbox *sender=0,*fromBox=0; | 149 | mailimf_mailbox *sender=0,*fromBox=0; |
150 | mailimf_mailbox_list *from=0; | 150 | mailimf_mailbox_list *from=0; |
151 | mailimf_address_list *to=0, *cc=0, *bcc=0, *reply=0; | 151 | mailimf_address_list *to=0, *cc=0, *bcc=0, *reply=0; |
152 | clist*in_reply_to = 0; | ||
152 | char *subject = strdup( mail.getSubject().latin1() ); | 153 | char *subject = strdup( mail.getSubject().latin1() ); |
153 | int err; | 154 | int err; |
154 | 155 | ||
155 | sender = newMailbox( mail.getName(), mail.getMail() ); | 156 | sender = newMailbox( mail.getName(), mail.getMail() ); |
156 | if ( sender == NULL ) | 157 | if ( sender == NULL ) |
157 | goto err_free; | 158 | goto err_free; |
158 | 159 | ||
159 | fromBox = newMailbox( mail.getName(), mail.getMail() ); | 160 | fromBox = newMailbox( mail.getName(), mail.getMail() ); |
160 | if ( fromBox == NULL ) | 161 | if ( fromBox == NULL ) |
161 | goto err_free_sender; | 162 | goto err_free_sender; |
162 | 163 | ||
163 | from = mailimf_mailbox_list_new_empty(); | 164 | from = mailimf_mailbox_list_new_empty(); |
164 | if ( from == NULL ) | 165 | if ( from == NULL ) |
165 | goto err_free_fromBox; | 166 | goto err_free_fromBox; |
166 | 167 | ||
167 | err = mailimf_mailbox_list_add( from, fromBox ); | 168 | err = mailimf_mailbox_list_add( from, fromBox ); |
168 | if ( err != MAILIMF_NO_ERROR ) | 169 | if ( err != MAILIMF_NO_ERROR ) |
169 | goto err_free_from; | 170 | goto err_free_from; |
170 | 171 | ||
171 | to = parseAddresses( mail.getTo() ); | 172 | to = parseAddresses( mail.getTo() ); |
172 | if ( to == NULL ) | 173 | if ( to == NULL ) |
173 | goto err_free_from; | 174 | goto err_free_from; |
174 | 175 | ||
175 | cc = parseAddresses( mail.getCC() ); | 176 | cc = parseAddresses( mail.getCC() ); |
176 | bcc = parseAddresses( mail.getBCC() ); | 177 | bcc = parseAddresses( mail.getBCC() ); |
177 | reply = parseAddresses( mail.getReply() ); | 178 | reply = parseAddresses( mail.getReply() ); |
178 | 179 | ||
180 | if (mail.Inreply().count()>0) { | ||
181 | in_reply_to = clist_new(); | ||
182 | char*c_reply; | ||
183 | unsigned int nsize = 0; | ||
184 | for (QStringList::ConstIterator it=mail.Inreply().begin(); | ||
185 | it != mail.Inreply().end();++it) { | ||
186 | /* yes! must be malloc! */ | ||
187 | if ((*it).isEmpty()) | ||
188 | continue; | ||
189 | QString h((*it)); | ||
190 | while (h.length()>0 && h[0]=='<') { | ||
191 | h.remove(0,1); | ||
192 | } | ||
193 | while (h.length()>0 && h[h.length()-1]=='>') { | ||
194 | h.remove(h.length()-1,1); | ||
195 | } | ||
196 | if (h.isEmpty()) continue; | ||
197 | nsize = strlen(h.latin1()); | ||
198 | c_reply = (char*)malloc( (nsize+1)*sizeof(char)); | ||
199 | memset(c_reply,0,nsize+1); | ||
200 | memcpy(c_reply,h.latin1(),nsize); | ||
201 | clist_append(in_reply_to,c_reply); | ||
202 | qDebug("In reply to: %s",c_reply); | ||
203 | } | ||
204 | } | ||
205 | |||
179 | fields = mailimf_fields_new_with_data( from, sender, reply, to, cc, bcc, | 206 | fields = mailimf_fields_new_with_data( from, sender, reply, to, cc, bcc, |
180 | NULL, NULL, subject ); | 207 | in_reply_to, NULL, subject ); |
181 | if ( fields == NULL ) | 208 | if ( fields == NULL ) |
182 | goto err_free_reply; | 209 | goto err_free_reply; |
183 | 210 | ||
184 | xmailer = mailimf_field_new_custom( strdup( "User-Agent" ), | 211 | xmailer = mailimf_field_new_custom( strdup( "User-Agent" ), |
185 | strdup( USER_AGENT ) ); | 212 | strdup( USER_AGENT ) ); |
186 | if ( xmailer == NULL ) | 213 | if ( xmailer == NULL ) |
187 | goto err_free_fields; | 214 | goto err_free_fields; |
188 | 215 | ||
189 | err = mailimf_fields_add( fields, xmailer ); | 216 | err = mailimf_fields_add( fields, xmailer ); |
190 | if ( err != MAILIMF_NO_ERROR ) | 217 | if ( err != MAILIMF_NO_ERROR ) |
191 | goto err_free_xmailer; | 218 | goto err_free_xmailer; |
192 | 219 | ||
193 | return fields; // Success :) | 220 | return fields; // Success :) |
194 | 221 | ||
195 | err_free_xmailer: | 222 | err_free_xmailer: |
196 | if (xmailer) | 223 | if (xmailer) |
197 | mailimf_field_free( xmailer ); | 224 | mailimf_field_free( xmailer ); |
198 | err_free_fields: | 225 | err_free_fields: |
199 | if (fields) | 226 | if (fields) |
200 | mailimf_fields_free( fields ); | 227 | mailimf_fields_free( fields ); |
201 | err_free_reply: | 228 | err_free_reply: |
202 | if (reply) | 229 | if (reply) |
203 | mailimf_address_list_free( reply ); | 230 | mailimf_address_list_free( reply ); |
204 | if (bcc) | 231 | if (bcc) |
205 | mailimf_address_list_free( bcc ); | 232 | mailimf_address_list_free( bcc ); |
206 | if (cc) | 233 | if (cc) |
207 | mailimf_address_list_free( cc ); | 234 | mailimf_address_list_free( cc ); |
208 | if (to) | 235 | if (to) |
209 | mailimf_address_list_free( to ); | 236 | mailimf_address_list_free( to ); |
210 | err_free_from: | 237 | err_free_from: |
211 | if (from) | 238 | if (from) |
212 | mailimf_mailbox_list_free( from ); | 239 | mailimf_mailbox_list_free( from ); |
213 | err_free_fromBox: | 240 | err_free_fromBox: |
214 | mailimf_mailbox_free( fromBox ); | 241 | mailimf_mailbox_free( fromBox ); |
215 | err_free_sender: | 242 | err_free_sender: |
216 | if (sender) | 243 | if (sender) |
217 | mailimf_mailbox_free( sender ); | 244 | mailimf_mailbox_free( sender ); |
218 | err_free: | 245 | err_free: |
219 | if (subject) | 246 | if (subject) |
220 | free( subject ); | 247 | free( subject ); |
221 | qDebug( "createImfFields - error" ); | 248 | qDebug( "createImfFields - error" ); |
222 | 249 | ||
223 | return NULL; // Error :( | 250 | return NULL; // Error :( |
224 | } | 251 | } |
225 | 252 | ||
226 | mailmime *SMTPwrapper::buildTxtPart(const QString&str ) { | 253 | mailmime *SMTPwrapper::buildTxtPart(const QString&str ) { |
227 | mailmime *txtPart; | 254 | mailmime *txtPart; |
228 | mailmime_fields *fields; | 255 | mailmime_fields *fields; |