summaryrefslogtreecommitdiffabout
path: root/kmicromail/libmailwrapper/storemail.cpp
blob: 9d1735fd0728cfa60a33c60f4cee3bf9b07c0288 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include "storemail.h"
#include "mailwrapper.h"
#include "settings.h"
#include "abstractmail.h"

#include <libetpan/libetpan.h>
#include <qstring.h>

#include <stdlib.h>
#include <kglobal.h>

using namespace Opie::Core;
Storemail::Storemail(Account*aAccount,const QString&aFolder)
    : Generatemail()
{
    wrapper = 0;
    m_Account = aAccount;
    m_tfolder = aFolder;
    wrapper = AbstractMail::getWrapper(m_Account);
    if (wrapper) {
        wrapper->createMbox(m_tfolder);
    }
}

Storemail::Storemail(const QString&dir,const QString&aFolder)
    : Generatemail()
{
    wrapper = 0;
    m_Account = 0;
    m_tfolder = aFolder;
    wrapper = AbstractMail::getWrapper(dir);
    if (wrapper) {
        wrapper->createMbox(m_tfolder);
    }
}

Storemail::Storemail(const QString&aFolder)
    : Generatemail()
{
    wrapper = 0;
    m_Account = 0;
    m_tfolder = aFolder;
    wrapper = AbstractMail::getWrapper(AbstractMail::defaultLocalfolder());
    if (wrapper) {
        wrapper->createMbox(m_tfolder);
    }
}

Storemail::~Storemail()
{
}

int Storemail::storeMail(const Opie::Core::OSmartPointer<Mail>&mail)
{
    if (!wrapper) return 0;
    int ret = 1;

    mailmime * mimeMail = 0;
    mimeMail = createMimeMail(mail );
    if ( mimeMail == NULL ) {
        qDebug("storeMail: error creating mime mail ");
        return 0;
    }
    char *data;
    size_t size;
    data = 0;

    mailmessage * msg = 0;
    msg = mime_message_init(mimeMail); 
    QString fileName;
#ifdef DESKTOP_VERSION
    fileName = locateLocal("tmp", "");
#else
    fileName = "/tmp/";
#endif
    //mime_message_set_tmpdir(msg,getenv( "HOME" ));
    mime_message_set_tmpdir(msg,(char*)fileName.latin1());
    int r = mailmessage_fetch(msg,&data,&size);
    mime_message_detach_mime(msg);
    mailmessage_free(msg);
    msg = 0;
    if (r != MAIL_NO_ERROR || !data) {
        qDebug("Error fetching mime... ");
        ret = 0;
    }

    if (ret) {
        wrapper->storeMessage(data,size,m_tfolder);
    }

    if (data) {
        free(data);
    }
    if (mimeMail) {
        mailmime_free( mimeMail );
    }
    return ret;
}