summaryrefslogtreecommitdiffabout
path: root/kmicromail/libmailwrapper/storemail.cpp
Unidiff
Diffstat (limited to 'kmicromail/libmailwrapper/storemail.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kmicromail/libmailwrapper/storemail.cpp90
1 files changed, 90 insertions, 0 deletions
diff --git a/kmicromail/libmailwrapper/storemail.cpp b/kmicromail/libmailwrapper/storemail.cpp
new file mode 100644
index 0000000..ed1d44a
--- a/dev/null
+++ b/kmicromail/libmailwrapper/storemail.cpp
@@ -0,0 +1,90 @@
1#include "storemail.h"
2#include "mailwrapper.h"
3#include "settings.h"
4#include "abstractmail.h"
5
6#include <libetpan/libetpan.h>
7#include <qstring.h>
8
9#include <stdlib.h>
10
11using namespace Opie::Core;
12Storemail::Storemail(Account*aAccount,const QString&aFolder)
13 : Generatemail()
14{
15 wrapper = 0;
16 m_Account = aAccount;
17 m_tfolder = aFolder;
18 wrapper = AbstractMail::getWrapper(m_Account);
19 if (wrapper) {
20 wrapper->createMbox(m_tfolder);
21 }
22}
23
24Storemail::Storemail(const QString&dir,const QString&aFolder)
25 : Generatemail()
26{
27 wrapper = 0;
28 m_Account = 0;
29 m_tfolder = aFolder;
30 wrapper = AbstractMail::getWrapper(dir);
31 if (wrapper) {
32 wrapper->createMbox(m_tfolder);
33 }
34}
35
36Storemail::Storemail(const QString&aFolder)
37 : Generatemail()
38{
39 wrapper = 0;
40 m_Account = 0;
41 m_tfolder = aFolder;
42 wrapper = AbstractMail::getWrapper(AbstractMail::defaultLocalfolder());
43 if (wrapper) {
44 wrapper->createMbox(m_tfolder);
45 }
46}
47
48Storemail::~Storemail()
49{
50}
51
52int Storemail::storeMail(const Opie::Core::OSmartPointer<Mail>&mail)
53{
54 if (!wrapper) return 0;
55 int ret = 1;
56
57 mailmime * mimeMail = 0;
58 mimeMail = createMimeMail(mail );
59 if ( mimeMail == NULL ) {
60 qDebug("storeMail: error creating mime mail ");
61 return 0;
62 }
63 char *data;
64 size_t size;
65 data = 0;
66
67 mailmessage * msg = 0;
68 msg = mime_message_init(mimeMail);
69 mime_message_set_tmpdir(msg,getenv( "HOME" ));
70 int r = mailmessage_fetch(msg,&data,&size);
71 mime_message_detach_mime(msg);
72 mailmessage_free(msg);
73 msg = 0;
74 if (r != MAIL_NO_ERROR || !data) {
75 qDebug("Error fetching mime... ");
76 ret = 0;
77 }
78
79 if (ret) {
80 wrapper->storeMessage(data,size,m_tfolder);
81 }
82
83 if (data) {
84 free(data);
85 }
86 if (mimeMail) {
87 mailmime_free( mimeMail );
88 }
89 return ret;
90}