|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the Qt Mobility Components. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 #include <QDebug> |
|
43 #include <QDir> |
|
44 #include <QDirIterator> |
|
45 #include <QtDBus> |
|
46 |
|
47 #include <qmessage.h> |
|
48 #include <qmessagemanager.h> |
|
49 #include <qmessage_p.h> |
|
50 |
|
51 #include <glib.h> |
|
52 #include <gconf/gconf-client.h> |
|
53 |
|
54 #include "support.h" |
|
55 |
|
56 // Service names for qtm-modest-plugin |
|
57 #define MODESTENGINE_QTM_PLUGIN_PATH "/com/nokia/Qtm/Modest/Plugin" |
|
58 #define MODESTENGINE_QTM_PLUGIN_NAME "com.nokia.Qtm.Modest.Plugin" |
|
59 |
|
60 // Constants |
|
61 const char TST_ACCOUNTS_PATH[] = "/apps/modest/accounts/"; |
|
62 const char TST_SERVER_ACCOUNTS_PATH[] = "/apps/modest/server_accounts/"; |
|
63 const char TST_STORE_ACCOUNT_KEY[] = "store_account"; |
|
64 const char TST_TRANSPORT_ACCOUNT_KEY[] = "transport_account"; |
|
65 |
|
66 // Maybe it would be better to just nuke everything? |
|
67 #define NAME_COUNT 6 |
|
68 const char *TST_ACCOUNT_NAMES[NAME_COUNT] = { |
|
69 "testAccountID", |
|
70 "Test Account #1ID", |
|
71 "Test Account #2ID", |
|
72 "Alter EgoID", |
|
73 "PersonalID", |
|
74 "WorkID" |
|
75 }; |
|
76 |
|
77 // Prints and clears an error |
|
78 static void |
|
79 printError (const char *fname, const int &line, GError **error); |
|
80 |
|
81 // Removes test accounts |
|
82 static void |
|
83 clearTestAccounts (); |
|
84 |
|
85 // Get a valid GConf key for account name |
|
86 static QString |
|
87 getAccountKey (const Support::Parameters ¶ms, const bool &escape); |
|
88 |
|
89 // Gets a valid account path for GConf from parameters |
|
90 static QString |
|
91 getAccountPath (const Support::Parameters ¶ms, const bool &escape); |
|
92 |
|
93 QTM_BEGIN_NAMESPACE |
|
94 class MapiSession |
|
95 { |
|
96 public: |
|
97 static QMessageId addMessage(const Support::Parameters ¶ms); |
|
98 }; |
|
99 |
|
100 // The class 'MapiSession' is a friend of QMessageContentContainer - hijack it here |
|
101 // => This is needed to make it possible to set parentFolderId |
|
102 QMessageId MapiSession::addMessage(const Support::Parameters ¶ms) |
|
103 { |
|
104 QString parentAccountName(params["parentAccountName"]); |
|
105 QString parentFolderPath(params["parentFolderPath"]); |
|
106 QString to(params["to"]); |
|
107 QString cc(params["cc"]); |
|
108 QString from(params["from"]); |
|
109 QString date(params["date"]); |
|
110 QString receivedDate(params["receivedDate"]); |
|
111 QString subject(params["subject"]); |
|
112 QString text(params["text"]); |
|
113 QString mimeType(params["mimeType"]); |
|
114 QString attachments(params["attachments"]); |
|
115 QString priority(params["priority"]); |
|
116 QString size(params["size"]); |
|
117 QString type(params["type"]); |
|
118 QString read(params["status-read"]); |
|
119 QString hasAttachments(params["status-hasAttachments"]); |
|
120 |
|
121 QMessageManager manager; |
|
122 |
|
123 if (!to.isEmpty() && !from.isEmpty() && !date.isEmpty() && !subject.isEmpty() && |
|
124 !parentAccountName.isEmpty() && !parentFolderPath.isEmpty()) { |
|
125 // Find the named account |
|
126 QMessageAccountIdList accountIds(manager.queryAccounts(QMessageAccountFilter::byName(parentAccountName))); |
|
127 if (accountIds.count() == 1) { |
|
128 // Find the specified folder |
|
129 QMessageFolderFilter filter(QMessageFolderFilter::byName(parentFolderPath) & QMessageFolderFilter::byParentAccountId(accountIds.first())); |
|
130 QMessageFolderIdList folderIds(manager.queryFolders(filter)); |
|
131 if (folderIds.count() == 1) { |
|
132 QMessage message; |
|
133 |
|
134 message.setParentAccountId(accountIds.first()); |
|
135 message.d_ptr->_parentFolderId = folderIds.first(); |
|
136 |
|
137 QList<QMessageAddress> toList; |
|
138 foreach (const QString &addr, to.split(",")) { |
|
139 toList.append(QMessageAddress(QMessageAddress::Email, addr.trimmed())); |
|
140 } |
|
141 message.setTo(toList); |
|
142 |
|
143 QList<QMessageAddress> ccList; |
|
144 foreach (const QString &addr, cc.split(",")) { |
|
145 if (!addr.isEmpty()) { |
|
146 ccList.append(QMessageAddress(QMessageAddress::Email, addr.trimmed())); |
|
147 } |
|
148 } |
|
149 message.setCc(ccList); |
|
150 |
|
151 message.setFrom(QMessageAddress(QMessageAddress::Email, from)); |
|
152 message.setSubject(subject); |
|
153 |
|
154 QDateTime dt(QDateTime::fromString(date, Qt::ISODate)); |
|
155 dt.setTimeSpec(Qt::UTC); |
|
156 message.setDate(dt); |
|
157 |
|
158 if (type.isEmpty()) { |
|
159 message.setType(QMessage::Email); |
|
160 } else { |
|
161 if (type.toLower() == "mms") { |
|
162 message.setType(QMessage::Mms); |
|
163 } else if (type.toLower() == "sms") { |
|
164 message.setType(QMessage::Sms); |
|
165 } else if (type.toLower() == "instantmessage") { |
|
166 message.setType(QMessage::InstantMessage); |
|
167 } else { |
|
168 message.setType(QMessage::Email); |
|
169 } |
|
170 } |
|
171 |
|
172 if (!receivedDate.isEmpty()) { |
|
173 QDateTime dt(QDateTime::fromString(receivedDate, Qt::ISODate)); |
|
174 dt.setTimeSpec(Qt::UTC); |
|
175 message.setReceivedDate(dt); |
|
176 } |
|
177 |
|
178 if (!priority.isEmpty()) { |
|
179 if (priority.toLower() == "high") { |
|
180 message.setPriority(QMessage::HighPriority); |
|
181 } else if (priority.toLower() == "low") { |
|
182 message.setPriority(QMessage::LowPriority); |
|
183 } |
|
184 } |
|
185 |
|
186 /*if (!size.isEmpty()) { |
|
187 message.d_ptr->_size = size.toUInt(); |
|
188 }*/ |
|
189 |
|
190 if (!text.isEmpty()) { |
|
191 message.setBody(text, mimeType.toAscii()); |
|
192 } |
|
193 |
|
194 if (!attachments.isEmpty()) { |
|
195 message.appendAttachments(attachments.split("\n")); |
|
196 } |
|
197 |
|
198 QMessage::StatusFlags flags(0); |
|
199 if (read.toLower() == "true") { |
|
200 flags |= QMessage::Read; |
|
201 } |
|
202 if (hasAttachments.toLower() == "true") { |
|
203 flags |= QMessage::HasAttachments; |
|
204 } |
|
205 message.setStatus(flags); |
|
206 |
|
207 if (!manager.addMessage(&message)) { |
|
208 qWarning() << "Unable to addMessage:" << to << from << date << subject; |
|
209 } else { |
|
210 return message.id(); |
|
211 } |
|
212 } else { |
|
213 qWarning() << "Unable to locate parent folder:" << parentFolderPath; |
|
214 } |
|
215 } else { |
|
216 qWarning() << "Unable to locate parent account:" << parentAccountName; |
|
217 } |
|
218 } else { |
|
219 qWarning() << "Necessary information missing"; |
|
220 } |
|
221 |
|
222 return QMessageId(); |
|
223 } |
|
224 QTM_END_NAMESPACE |
|
225 |
|
226 static void |
|
227 printError ( |
|
228 const char *fname, |
|
229 const int &line, |
|
230 GError **error) |
|
231 { |
|
232 GError *err = NULL; |
|
233 |
|
234 if (error == NULL || *error == NULL) return; |
|
235 err = *error; |
|
236 |
|
237 qWarning() << "Error in " << fname << ", line: " << line << endl |
|
238 << "Domain: " << g_quark_to_string (err->domain) << endl |
|
239 << "Code: " << err->code << endl |
|
240 << "Message: " << err->message; |
|
241 g_clear_error (error); |
|
242 } |
|
243 |
|
244 // Clears test accounts |
|
245 static void |
|
246 clearTestAccounts () |
|
247 { |
|
248 GConfClient *client = NULL; |
|
249 GError *err = NULL; |
|
250 gboolean unset = FALSE; |
|
251 uint unset_flags = 0; |
|
252 const char *key = NULL; |
|
253 uint i; |
|
254 gchar *store_account = NULL; |
|
255 gchar *transport_account = NULL; |
|
256 |
|
257 client = gconf_client_get_default (); |
|
258 |
|
259 for (i = 0; i < NAME_COUNT; i++) { |
|
260 QString str, path; |
|
261 gchar *escaped; |
|
262 |
|
263 key = TST_ACCOUNT_NAMES[i]; |
|
264 escaped = gconf_escape_key (key, -1); |
|
265 |
|
266 path = QString::fromUtf8 (TST_ACCOUNTS_PATH); |
|
267 path.append (escaped); |
|
268 |
|
269 str = path; |
|
270 str.append ("/"); |
|
271 str.append (TST_STORE_ACCOUNT_KEY); |
|
272 |
|
273 qDebug() << "Fetching key value from: " << str; |
|
274 |
|
275 store_account = gconf_client_get_string ( |
|
276 client, str.toLocal8Bit().data(), &err); |
|
277 |
|
278 if (err != NULL || store_account == NULL) { |
|
279 if (err != NULL) |
|
280 printError (__FUNCTION__, __LINE__, &err); |
|
281 qWarning() << "Failed to get GConf key value " << str; |
|
282 } else if (store_account) { |
|
283 gchar *temp = gconf_escape_key (store_account, -1); |
|
284 |
|
285 str = QString::fromUtf8 (TST_SERVER_ACCOUNTS_PATH); |
|
286 str.append (temp); |
|
287 |
|
288 qDebug() << "Unsetting value from: " << str; |
|
289 |
|
290 unset = gconf_client_recursive_unset ( |
|
291 client, |
|
292 str.toLocal8Bit().data(), |
|
293 (GConfUnsetFlags)unset_flags, |
|
294 &err); |
|
295 |
|
296 if (err != NULL) { |
|
297 printError (__FUNCTION__, __LINE__, &err); |
|
298 } |
|
299 if (unset == FALSE) { |
|
300 qWarning() << "Failed to unset GConf dir " << str; |
|
301 } |
|
302 g_free (temp); |
|
303 temp = NULL; |
|
304 } |
|
305 |
|
306 str = path; |
|
307 str.append ("/"); |
|
308 str.append (TST_TRANSPORT_ACCOUNT_KEY); |
|
309 |
|
310 qDebug() << "Fetching key value from: " << str; |
|
311 |
|
312 transport_account = gconf_client_get_string ( |
|
313 client, str.toLocal8Bit().data(), &err); |
|
314 |
|
315 if (err != NULL || transport_account == NULL) { |
|
316 if (err != NULL) |
|
317 printError (__FUNCTION__, __LINE__, &err); |
|
318 qWarning() << "Failed to get GConf key value " << str; |
|
319 } else if (transport_account) { |
|
320 gchar *temp = gconf_escape_key (transport_account, -1); |
|
321 |
|
322 str = QString::fromUtf8 (TST_SERVER_ACCOUNTS_PATH); |
|
323 str.append (temp); |
|
324 |
|
325 qDebug() << "Unsetting value from: " << str; |
|
326 |
|
327 unset = gconf_client_recursive_unset ( |
|
328 client, |
|
329 str.toLocal8Bit().data(), |
|
330 (GConfUnsetFlags)unset_flags, |
|
331 &err); |
|
332 |
|
333 if (err != NULL) { |
|
334 printError (__FUNCTION__, __LINE__, &err); |
|
335 } |
|
336 if (unset == FALSE) { |
|
337 qWarning() << "Failed to unset GConf dir " << str; |
|
338 } |
|
339 g_free (temp); |
|
340 temp = NULL; |
|
341 } |
|
342 |
|
343 qDebug() << "Unsetting account: " << path; |
|
344 |
|
345 unset = gconf_client_recursive_unset ( |
|
346 client, path.toLocal8Bit().data(), |
|
347 (GConfUnsetFlags)unset_flags, &err); |
|
348 |
|
349 if (err != NULL) { |
|
350 printError (__FUNCTION__, __LINE__, &err); |
|
351 } |
|
352 if (unset == FALSE) { |
|
353 qWarning() << "Failed to unset GConf dir " << path; |
|
354 } |
|
355 |
|
356 // Reserved with GLIB methods, free with GLIB methods |
|
357 g_free (escaped); |
|
358 escaped = NULL; |
|
359 |
|
360 g_free (store_account); |
|
361 store_account = NULL; |
|
362 |
|
363 g_free (transport_account); |
|
364 transport_account = NULL; |
|
365 } |
|
366 } |
|
367 |
|
368 // Get a valid GConf key for account name |
|
369 static QString |
|
370 getAccountKey (const Support::Parameters ¶ms, const bool &escape) |
|
371 { |
|
372 QString key; |
|
373 gchar *escaped; |
|
374 |
|
375 key = params["name"]; |
|
376 |
|
377 if (key.isEmpty() || key.isNull()) return key; |
|
378 |
|
379 // Modest compatability |
|
380 key.append ("ID"); |
|
381 |
|
382 if (escape == false) return key; |
|
383 |
|
384 escaped = gconf_escape_key (key.toLocal8Bit().data(), -1); |
|
385 |
|
386 qDebug() << "Escaped key: " << key << " to " << escaped; |
|
387 |
|
388 key = escaped; |
|
389 g_free (escaped); |
|
390 escaped = NULL; |
|
391 |
|
392 return key; |
|
393 } |
|
394 |
|
395 // Get a valid GConf path for account name |
|
396 static QString |
|
397 getAccountPath (const Support::Parameters ¶ms, const bool &escape) |
|
398 { |
|
399 QString key, path; |
|
400 |
|
401 // Escape the incoming name |
|
402 key = getAccountKey (params, escape); |
|
403 |
|
404 if (key.isEmpty() || key.isNull()) return key; |
|
405 |
|
406 // Match the accountName to a GConf key (it's how the account ids are) |
|
407 // formed... |
|
408 path = QString::fromUtf8 (TST_ACCOUNTS_PATH); |
|
409 path.append (key); |
|
410 |
|
411 return path; |
|
412 } |
|
413 |
|
414 namespace Support { |
|
415 |
|
416 void deltree(QString directory) |
|
417 { |
|
418 if (QDir(directory).exists()) { |
|
419 QDirIterator directoryIterator(directory, (QDir::AllEntries | QDir::NoDotAndDotDot)); |
|
420 while (directoryIterator.hasNext()) { |
|
421 QString path = directoryIterator.next(); |
|
422 QFileInfo fileInfo = directoryIterator.fileInfo(); |
|
423 if (fileInfo.isFile()) { |
|
424 QFile::remove(path); |
|
425 } else if (fileInfo.isDir()) { |
|
426 deltree(path); |
|
427 } |
|
428 } |
|
429 QDir dir; |
|
430 dir.rmdir(directory); |
|
431 } |
|
432 } |
|
433 |
|
434 // Clears test data, that we know about |
|
435 void clearMessageStore() |
|
436 { |
|
437 QString localRootFolder = QDir::home().absolutePath()+QString("/.modest/local_folders"); |
|
438 QStringList CREATED_FOLDERS = QStringList() << QString("Root") |
|
439 << QString("Unbox") |
|
440 << QString("Archived") |
|
441 << QString("Backup") |
|
442 << QString("My messages") |
|
443 << QString("Innbox") |
|
444 << QString("X-Announce") |
|
445 << QString("X-Archived"); |
|
446 |
|
447 QMessageFolderId folderId; |
|
448 |
|
449 QDBusInterface pluginDBusInterface(MODESTENGINE_QTM_PLUGIN_NAME, |
|
450 MODESTENGINE_QTM_PLUGIN_PATH, |
|
451 MODESTENGINE_QTM_PLUGIN_NAME, |
|
452 QDBusConnection::sessionBus()); |
|
453 |
|
454 for (int i=0; i < CREATED_FOLDERS.count(); i++) { |
|
455 QDBusPendingCall pendingCall = pluginDBusInterface.asyncCall("RemoveFolder", |
|
456 "local_folders", |
|
457 CREATED_FOLDERS[i]); |
|
458 QDBusPendingCallWatcher pendingCallWatcher(pendingCall); |
|
459 pendingCallWatcher.waitForFinished(); |
|
460 |
|
461 QDBusMessage msg = pendingCallWatcher.reply(); |
|
462 if (msg.type() != QDBusMessage::ReplyMessage) { |
|
463 break; |
|
464 } |
|
465 } |
|
466 |
|
467 clearTestAccounts (); |
|
468 } |
|
469 |
|
470 // Add, or modify an account |
|
471 QMessageAccountId addAccount (const Parameters ¶ms) |
|
472 { |
|
473 QString accountPath, accountKey, escapedAccountKey, accountName, address; |
|
474 QString confKey, confValue; |
|
475 GConfClient *client; |
|
476 GError *err = NULL; |
|
477 gboolean valueSet = FALSE; |
|
478 |
|
479 qDebug() << params; |
|
480 |
|
481 // Get escaped path for account id |
|
482 accountPath = getAccountPath (params, true); |
|
483 |
|
484 // Invalid? |
|
485 if (accountPath.isEmpty ()) return QMessageAccountId (); |
|
486 if (accountPath.isNull ()) return QMessageAccountId (); |
|
487 |
|
488 client = gconf_client_get_default (); |
|
489 |
|
490 accountName = params["name"]; |
|
491 address = params["fromAddress"]; |
|
492 accountKey = getAccountKey (params, false); |
|
493 escapedAccountKey = getAccountKey (params, true); |
|
494 |
|
495 // Display name |
|
496 confKey = accountPath; |
|
497 confKey.append ("/"); |
|
498 confKey.append ("display_name"); |
|
499 valueSet = gconf_client_set_string ( |
|
500 client, |
|
501 confKey.toLocal8Bit().data(), |
|
502 accountName.toLocal8Bit().data(), |
|
503 &err); |
|
504 |
|
505 if (valueSet == FALSE || err != NULL) { |
|
506 if (err != NULL) |
|
507 printError (__FUNCTION__, __LINE__, &err); |
|
508 qWarning() << "Failed to set display_name for " << accountName; |
|
509 return QMessageAccountId(); |
|
510 } |
|
511 |
|
512 // Email |
|
513 confKey = accountPath; |
|
514 confKey.append ("/"); |
|
515 confKey.append ("email"); |
|
516 valueSet = gconf_client_set_string ( |
|
517 client, |
|
518 confKey.toLocal8Bit().data(), |
|
519 address.toLocal8Bit().data(), |
|
520 &err); |
|
521 |
|
522 if (valueSet == FALSE || err != NULL) { |
|
523 if (err != NULL) |
|
524 printError (__FUNCTION__, __LINE__, &err); |
|
525 qWarning() << "Failed to set email for " << accountName; |
|
526 return QMessageAccountId(); |
|
527 } |
|
528 |
|
529 // Enabled |
|
530 confKey = accountPath; |
|
531 confKey.append ("/"); |
|
532 confKey.append ("enabled"); |
|
533 valueSet = gconf_client_set_bool ( |
|
534 client, |
|
535 confKey.toLocal8Bit().data(), |
|
536 TRUE, |
|
537 &err); |
|
538 |
|
539 if (valueSet == FALSE || err != NULL) { |
|
540 if (err != NULL) |
|
541 printError (__FUNCTION__, __LINE__, &err); |
|
542 qWarning() << "Failed to set enabled for " << accountName; |
|
543 return QMessageAccountId(); |
|
544 } |
|
545 |
|
546 // Signature |
|
547 confKey = accountPath; |
|
548 confKey.append ("/"); |
|
549 confKey.append ("signature"); |
|
550 valueSet = gconf_client_set_string ( |
|
551 client, |
|
552 confKey.toLocal8Bit().data(), |
|
553 "", |
|
554 &err); |
|
555 |
|
556 if (valueSet == FALSE || err != NULL) { |
|
557 if (err != NULL) |
|
558 printError (__FUNCTION__, __LINE__, &err); |
|
559 qWarning() << "Failed to set signature for " << accountName; |
|
560 return QMessageAccountId(); |
|
561 } |
|
562 |
|
563 // Limit retrieve |
|
564 confKey = accountPath; |
|
565 confKey.append ("/"); |
|
566 confKey.append ("limit-retrieve"); |
|
567 valueSet = gconf_client_set_int ( |
|
568 client, |
|
569 confKey.toLocal8Bit().data(), |
|
570 20, |
|
571 &err); |
|
572 |
|
573 if (valueSet == FALSE || err != NULL) { |
|
574 if (err != NULL) |
|
575 printError (__FUNCTION__, __LINE__, &err); |
|
576 qWarning() << "Failed to set retrieve limit for " << accountName; |
|
577 return QMessageAccountId(); |
|
578 } |
|
579 |
|
580 // Retrieve |
|
581 confKey = accountPath; |
|
582 confKey.append ("/"); |
|
583 confKey.append ("retrieve"); |
|
584 valueSet = gconf_client_set_string ( |
|
585 client, |
|
586 confKey.toLocal8Bit().data(), |
|
587 "messages-and-attachments", |
|
588 &err); |
|
589 |
|
590 if (valueSet == FALSE || err != NULL) { |
|
591 if (err != NULL) |
|
592 printError (__FUNCTION__, __LINE__, &err); |
|
593 qWarning() << "Failed to set retrieve value for " << accountName; |
|
594 return QMessageAccountId(); |
|
595 } |
|
596 |
|
597 // Use specific SMTP |
|
598 confKey = accountPath; |
|
599 confKey.append ("/"); |
|
600 confKey.append ("use_specific_smtp"); |
|
601 valueSet = gconf_client_set_bool ( |
|
602 client, |
|
603 confKey.toLocal8Bit().data(), |
|
604 FALSE, |
|
605 &err); |
|
606 |
|
607 if (valueSet == FALSE || err != NULL) { |
|
608 if (err != NULL) |
|
609 printError (__FUNCTION__, __LINE__, &err); |
|
610 qWarning() << "Failed to set specific smtp for " << accountName; |
|
611 return QMessageAccountId(); |
|
612 } |
|
613 |
|
614 // Should the account leave mails to server |
|
615 confKey = accountPath; |
|
616 confKey.append ("/"); |
|
617 confKey.append ("leave_on_server"); |
|
618 valueSet = gconf_client_set_bool ( |
|
619 client, |
|
620 confKey.toLocal8Bit().data(), |
|
621 TRUE, |
|
622 &err); |
|
623 |
|
624 if (valueSet == FALSE || err != NULL) { |
|
625 if (err != NULL) |
|
626 printError (__FUNCTION__, __LINE__, &err); |
|
627 qWarning() << "Failed to set leave on server for " << accountName; |
|
628 return QMessageAccountId(); |
|
629 } |
|
630 |
|
631 // Full name |
|
632 confKey = accountPath; |
|
633 confKey.append ("/"); |
|
634 confKey.append ("fullname"); |
|
635 valueSet = gconf_client_set_string ( |
|
636 client, |
|
637 confKey.toLocal8Bit().data(), |
|
638 accountName.toLocal8Bit().data(), |
|
639 &err); |
|
640 |
|
641 if (valueSet == FALSE || err != NULL) { |
|
642 if (err != NULL) |
|
643 printError (__FUNCTION__, __LINE__, &err); |
|
644 qWarning() << "Failed to set fullname for " << accountName; |
|
645 return QMessageAccountId(); |
|
646 } |
|
647 |
|
648 // Should the account use signature |
|
649 confKey = accountPath; |
|
650 confKey.append ("/"); |
|
651 confKey.append ("use_signature"); |
|
652 valueSet = gconf_client_set_bool ( |
|
653 client, |
|
654 confKey.toLocal8Bit().data(), |
|
655 FALSE, |
|
656 &err); |
|
657 |
|
658 if (valueSet == FALSE || err != NULL) { |
|
659 if (err != NULL) |
|
660 printError (__FUNCTION__, __LINE__, &err); |
|
661 qWarning() << "Failed to set signature use for " << accountName; |
|
662 return QMessageAccountId(); |
|
663 } |
|
664 |
|
665 |
|
666 // Store account (aka where to fetch accounts) |
|
667 confKey = accountPath; |
|
668 confKey.append ("/"); |
|
669 confKey.append (TST_STORE_ACCOUNT_KEY); |
|
670 |
|
671 confValue = accountKey; |
|
672 confValue.append ("_store"); |
|
673 |
|
674 valueSet = gconf_client_set_string ( |
|
675 client, |
|
676 confKey.toLocal8Bit().data(), |
|
677 confValue.toLocal8Bit().data(), |
|
678 &err); |
|
679 |
|
680 if (valueSet == FALSE || err != NULL) { |
|
681 if (err != NULL) |
|
682 printError (__FUNCTION__, __LINE__, &err); |
|
683 qWarning() << "Failed to set store account for " << accountName; |
|
684 return QMessageAccountId(); |
|
685 } |
|
686 |
|
687 // Used protocol |
|
688 confKey = TST_SERVER_ACCOUNTS_PATH; |
|
689 confKey.append (escapedAccountKey); |
|
690 confKey.append ("_store"); |
|
691 confKey.append ("/"); |
|
692 confKey.append ("proto"); |
|
693 |
|
694 valueSet = gconf_client_set_string ( |
|
695 client, |
|
696 confKey.toLocal8Bit().data(), |
|
697 "pop", |
|
698 &err); |
|
699 |
|
700 if (valueSet == FALSE || err != NULL) { |
|
701 if (err != NULL) |
|
702 printError (__FUNCTION__, __LINE__, &err); |
|
703 qWarning() << "Failed to set protocol for " << accountName; |
|
704 return QMessageAccountId(); |
|
705 } |
|
706 |
|
707 // Port |
|
708 confKey = TST_SERVER_ACCOUNTS_PATH; |
|
709 confKey.append (escapedAccountKey); |
|
710 confKey.append ("_store"); |
|
711 confKey.append ("/"); |
|
712 confKey.append ("port"); |
|
713 |
|
714 valueSet = gconf_client_set_int ( |
|
715 client, |
|
716 confKey.toLocal8Bit().data(), |
|
717 110, |
|
718 &err); |
|
719 |
|
720 if (valueSet == FALSE || err != NULL) { |
|
721 if (err != NULL) |
|
722 printError (__FUNCTION__, __LINE__, &err); |
|
723 qWarning() << "Failed to set port for " << accountName; |
|
724 return QMessageAccountId(); |
|
725 } |
|
726 |
|
727 // Hostname to use |
|
728 confKey = TST_SERVER_ACCOUNTS_PATH; |
|
729 confKey.append (escapedAccountKey); |
|
730 confKey.append ("_store"); |
|
731 confKey.append ("/"); |
|
732 confKey.append ("hostname"); |
|
733 |
|
734 valueSet = gconf_client_set_string ( |
|
735 client, |
|
736 confKey.toLocal8Bit().data(), |
|
737 "pop.example.com", |
|
738 &err); |
|
739 |
|
740 if (valueSet == FALSE || err != NULL) { |
|
741 if (err != NULL) |
|
742 printError (__FUNCTION__, __LINE__, &err); |
|
743 qWarning() << "Failed to set hostname for " << accountName; |
|
744 return QMessageAccountId(); |
|
745 } |
|
746 |
|
747 // Username to use |
|
748 confKey = TST_SERVER_ACCOUNTS_PATH; |
|
749 confKey.append (escapedAccountKey); |
|
750 confKey.append ("_store"); |
|
751 confKey.append ("/"); |
|
752 confKey.append ("username"); |
|
753 |
|
754 valueSet = gconf_client_set_string ( |
|
755 client, |
|
756 confKey.toLocal8Bit().data(), |
|
757 "tester", |
|
758 &err); |
|
759 |
|
760 if (valueSet == FALSE || err != NULL) { |
|
761 if (err != NULL) |
|
762 printError (__FUNCTION__, __LINE__, &err); |
|
763 qWarning() << "Failed to set username on store for " << accountName; |
|
764 return QMessageAccountId(); |
|
765 } |
|
766 |
|
767 // Authorization mechanism? |
|
768 confKey = TST_SERVER_ACCOUNTS_PATH; |
|
769 confKey.append (escapedAccountKey); |
|
770 confKey.append ("_store"); |
|
771 confKey.append ("/"); |
|
772 confKey.append ("auth_mech"); |
|
773 |
|
774 valueSet = gconf_client_set_string ( |
|
775 client, |
|
776 confKey.toLocal8Bit().data(), |
|
777 "none", |
|
778 &err); |
|
779 |
|
780 if (valueSet == FALSE || err != NULL) { |
|
781 if (err != NULL) |
|
782 printError (__FUNCTION__, __LINE__, &err); |
|
783 qWarning() << "Failed to set auth mechanism for " << accountName; |
|
784 return QMessageAccountId(); |
|
785 } |
|
786 |
|
787 // Password to use |
|
788 confKey = TST_SERVER_ACCOUNTS_PATH; |
|
789 confKey.append (escapedAccountKey); |
|
790 confKey.append ("_store"); |
|
791 confKey.append ("/"); |
|
792 confKey.append ("password"); |
|
793 |
|
794 valueSet = gconf_client_set_string ( |
|
795 client, |
|
796 confKey.toLocal8Bit().data(), |
|
797 "testerpassword", |
|
798 &err); |
|
799 |
|
800 if (valueSet == FALSE || err != NULL) { |
|
801 if (err != NULL) |
|
802 printError (__FUNCTION__, __LINE__, &err); |
|
803 qWarning() << "Failed to set password on store for " << accountName; |
|
804 return QMessageAccountId(); |
|
805 } |
|
806 |
|
807 // Security mechanism to use |
|
808 confKey = TST_SERVER_ACCOUNTS_PATH; |
|
809 confKey.append (escapedAccountKey); |
|
810 confKey.append ("_store"); |
|
811 confKey.append ("/"); |
|
812 confKey.append ("security"); |
|
813 |
|
814 valueSet = gconf_client_set_string ( |
|
815 client, |
|
816 confKey.toLocal8Bit().data(), |
|
817 "none", |
|
818 &err); |
|
819 |
|
820 if (valueSet == FALSE || err != NULL) { |
|
821 if (err != NULL) |
|
822 printError (__FUNCTION__, __LINE__, &err); |
|
823 qWarning() << "Failed to set security mechanism store for " |
|
824 << accountName; |
|
825 return QMessageAccountId(); |
|
826 } |
|
827 |
|
828 |
|
829 // Transport account (aka what to use to send) |
|
830 confKey = accountPath; |
|
831 confKey.append ("/"); |
|
832 confKey.append (TST_TRANSPORT_ACCOUNT_KEY); |
|
833 |
|
834 confValue = accountKey; |
|
835 confValue.append ("_transport"); |
|
836 |
|
837 valueSet = gconf_client_set_string ( |
|
838 client, |
|
839 confKey.toLocal8Bit().data(), |
|
840 confValue.toLocal8Bit().data(), |
|
841 &err); |
|
842 |
|
843 if (valueSet == FALSE || err != NULL) { |
|
844 if (err != NULL) |
|
845 printError (__FUNCTION__, __LINE__, &err); |
|
846 qWarning() << "Failed to set transport account for " << accountName; |
|
847 return QMessageAccountId(); |
|
848 } |
|
849 |
|
850 // Protocol for transport |
|
851 confKey = TST_SERVER_ACCOUNTS_PATH; |
|
852 confKey.append (escapedAccountKey); |
|
853 confKey.append ("_transport"); |
|
854 confKey.append ("/"); |
|
855 confKey.append ("proto"); |
|
856 |
|
857 valueSet = gconf_client_set_string ( |
|
858 client, |
|
859 confKey.toLocal8Bit().data(), |
|
860 "smtp", |
|
861 &err); |
|
862 |
|
863 if (valueSet == FALSE || err != NULL) { |
|
864 if (err != NULL) |
|
865 printError (__FUNCTION__, __LINE__, &err); |
|
866 qWarning() << "Failed to set transport protocol for " |
|
867 << accountName; |
|
868 return QMessageAccountId(); |
|
869 } |
|
870 |
|
871 // Port for transport |
|
872 confKey = TST_SERVER_ACCOUNTS_PATH; |
|
873 confKey.append (escapedAccountKey); |
|
874 confKey.append ("_transport"); |
|
875 confKey.append ("/"); |
|
876 confKey.append ("port"); |
|
877 |
|
878 valueSet = gconf_client_set_int ( |
|
879 client, |
|
880 confKey.toLocal8Bit().data(), |
|
881 25, |
|
882 &err); |
|
883 |
|
884 if (valueSet == FALSE || err != NULL) { |
|
885 if (err != NULL) |
|
886 printError (__FUNCTION__, __LINE__, &err); |
|
887 qWarning() << "Failed to set transport port for " |
|
888 << accountName; |
|
889 return QMessageAccountId(); |
|
890 } |
|
891 |
|
892 // Host for transport |
|
893 confKey = TST_SERVER_ACCOUNTS_PATH; |
|
894 confKey.append (escapedAccountKey); |
|
895 confKey.append ("_transport"); |
|
896 confKey.append ("/"); |
|
897 confKey.append ("hostname"); |
|
898 |
|
899 valueSet = gconf_client_set_string ( |
|
900 client, |
|
901 confKey.toLocal8Bit().data(), |
|
902 "smtp.example.com", |
|
903 &err); |
|
904 |
|
905 if (valueSet == FALSE || err != NULL) { |
|
906 if (err != NULL) |
|
907 printError (__FUNCTION__, __LINE__, &err); |
|
908 qWarning() << "Failed to set transport host for " |
|
909 << accountName; |
|
910 return QMessageAccountId(); |
|
911 } |
|
912 |
|
913 // Username for transport |
|
914 confKey = TST_SERVER_ACCOUNTS_PATH; |
|
915 confKey.append (escapedAccountKey); |
|
916 confKey.append ("_transport"); |
|
917 confKey.append ("/"); |
|
918 confKey.append ("username"); |
|
919 |
|
920 valueSet = gconf_client_set_string ( |
|
921 client, |
|
922 confKey.toLocal8Bit().data(), |
|
923 "tester", |
|
924 &err); |
|
925 |
|
926 if (valueSet == FALSE || err != NULL) { |
|
927 if (err != NULL) |
|
928 printError (__FUNCTION__, __LINE__, &err); |
|
929 qWarning() << "Failed to set transport username for " |
|
930 << accountName; |
|
931 return QMessageAccountId(); |
|
932 } |
|
933 |
|
934 // Password for transport |
|
935 confKey = TST_SERVER_ACCOUNTS_PATH; |
|
936 confKey.append (escapedAccountKey); |
|
937 confKey.append ("_transport"); |
|
938 confKey.append ("/"); |
|
939 confKey.append ("password"); |
|
940 |
|
941 valueSet = gconf_client_set_string ( |
|
942 client, |
|
943 confKey.toLocal8Bit().data(), |
|
944 "testerpassword", |
|
945 &err); |
|
946 |
|
947 if (valueSet == FALSE || err != NULL) { |
|
948 if (err != NULL) |
|
949 printError (__FUNCTION__, __LINE__, &err); |
|
950 qWarning() << "Failed to set transport password for " |
|
951 << accountName; |
|
952 return QMessageAccountId(); |
|
953 } |
|
954 |
|
955 // Authorization mechanism for transport |
|
956 confKey = TST_SERVER_ACCOUNTS_PATH; |
|
957 confKey.append (escapedAccountKey); |
|
958 confKey.append ("_transport"); |
|
959 confKey.append ("/"); |
|
960 confKey.append ("auth_mech"); |
|
961 |
|
962 valueSet = gconf_client_set_string ( |
|
963 client, |
|
964 confKey.toLocal8Bit().data(), |
|
965 "none", |
|
966 &err); |
|
967 |
|
968 if (valueSet == FALSE || err != NULL) { |
|
969 if (err != NULL) |
|
970 printError (__FUNCTION__, __LINE__, &err); |
|
971 qWarning() << "Failed to set transport auth mechanism for " |
|
972 << accountName; |
|
973 return QMessageAccountId(); |
|
974 } |
|
975 |
|
976 // Security mechanism for transport |
|
977 confKey = TST_SERVER_ACCOUNTS_PATH; |
|
978 confKey.append (escapedAccountKey); |
|
979 confKey.append ("_transport"); |
|
980 confKey.append ("/"); |
|
981 confKey.append ("security"); |
|
982 |
|
983 valueSet = gconf_client_set_string ( |
|
984 client, |
|
985 confKey.toLocal8Bit().data(), |
|
986 "none", |
|
987 &err); |
|
988 |
|
989 if (valueSet == FALSE || err != NULL) { |
|
990 if (err != NULL) |
|
991 printError (__FUNCTION__, __LINE__, &err); |
|
992 qWarning() << "Failed to set transport security for " |
|
993 << accountName; |
|
994 return QMessageAccountId(); |
|
995 } |
|
996 |
|
997 qDebug() << "Added account path " << accountPath << " with name " |
|
998 << accountName; |
|
999 |
|
1000 return QMessageAccountId ("MO_"+escapedAccountKey); |
|
1001 } |
|
1002 |
|
1003 // Add a folder, unless it already exists |
|
1004 QMessageFolderId addFolder(const Parameters ¶ms) |
|
1005 { |
|
1006 QString accountName(params["parentAccountName"]); |
|
1007 QString folderPath(params["path"]); |
|
1008 QString folderName(params["name"]); |
|
1009 |
|
1010 QMessageFolderId folderId; |
|
1011 |
|
1012 QDBusInterface pluginDBusInterface(MODESTENGINE_QTM_PLUGIN_NAME, |
|
1013 MODESTENGINE_QTM_PLUGIN_PATH, |
|
1014 MODESTENGINE_QTM_PLUGIN_NAME, |
|
1015 QDBusConnection::sessionBus()); |
|
1016 |
|
1017 QDBusPendingCall pendingCall = pluginDBusInterface.asyncCall("AddFolder", |
|
1018 "local_folders", |
|
1019 folderName); |
|
1020 QDBusPendingCallWatcher pendingCallWatcher(pendingCall); |
|
1021 pendingCallWatcher.waitForFinished(); |
|
1022 |
|
1023 // Escape account name (to be used in FolderId) |
|
1024 QString escapedAccountName; |
|
1025 gchar *escaped; |
|
1026 escaped = gconf_escape_key (accountName.toLocal8Bit().data(), -1); |
|
1027 escapedAccountName = escaped; |
|
1028 g_free (escaped); |
|
1029 |
|
1030 QDBusMessage msg = pendingCallWatcher.reply(); |
|
1031 if (msg.type() == QDBusMessage::ReplyMessage) { |
|
1032 folderId = QMessageFolderId("MO_"+escapedAccountName+"ID"+"&maildir&"+folderName); |
|
1033 } |
|
1034 |
|
1035 return folderId; |
|
1036 } |
|
1037 |
|
1038 // Add a message |
|
1039 QMessageId addMessage(const Parameters ¶ms) |
|
1040 { |
|
1041 return MapiSession::addMessage(params); |
|
1042 } |
|
1043 |
|
1044 }; // Namespace Support |