Skip to content

Commit

Permalink
05-26 14:27
Browse files Browse the repository at this point in the history
  • Loading branch information
stardust95 committed May 26, 2016
1 parent 7150ad7 commit 84045c3
Show file tree
Hide file tree
Showing 8 changed files with 412 additions and 169 deletions.
2 changes: 1 addition & 1 deletion MicroMailClient.pro.user
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 3.6.1, 2016-05-25T17:08:34. -->
<!-- Written by QtCreator 3.6.1, 2016-05-26T14:23:41. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>
Expand Down
52 changes: 40 additions & 12 deletions Model/IMAPClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class IMAPClient : public ReceiveMailClient

}

void getFolders(QList<QString> & _folders) override{
int getFolders(QList<QString> & _folders) override{

FolderInfoVec folders;

Expand All @@ -53,46 +53,71 @@ class IMAPClient : public ReceiveMailClient
_folders.push_back (QString::fromUtf8 (f.name.c_str()));
}

return folders.size ();
}

void getMailBodies(const QString & folder, QList<MAILBODY_PTR> & result) override{
int selectFolder(const QString & folder) override{

Poco::Net::IMAPClientSession::MessageInfoVec msgs;
_mailList.clear ();

std::vector<std::string> uids;

_selectedFolder = folder;

_session->listMessages (folder.toStdString (), uids);

_session->getMessages (folder.toStdString (), uids, msgs);
_session->getMessages (folder.toStdString (), uids, _mailList);

qDebug() << "In select Folder, folder = "<< folder << ", mailList.size = " << _mailList.size () << "uids.size = " << uids.size ()<< "\n";

_curListIndex = 0;

return uids.size ();

}

int getMailBodies(QList<MAILBODY_PTR> & result, int count ) override{

std::string msg;

for ( auto info : msgs) {
int counter = 0;

qDebug() << "listIndex = " <<_curListIndex << ", mailList.size=" << _mailList.size () << "\n";

for( ; _curListIndex < _mailList.size (); _curListIndex++, counter++) {

_session->loadMessage (folder.toStdString (), info, msg);
if( counter >= count )
break;

auto info = _mailList.at (_curListIndex);

_session->loadMessage (_selectedFolder.toStdString (), info, msg);

MAILBODY_PTR newmail = MAILBODY_PTR::create(QString::fromUtf8 (info.subject.c_str ()));

newmail->setContent (QString::fromUtf8 (msg.c_str ()));
newmail->setSender (QString::fromUtf8 (info.from.c_str()));
newmail->addRecipient (QString::fromUtf8 (info.to.c_str()));
newmail->setDateTime (QString::fromUtf8 (info.date.c_str()));
newmail->setIsread (false);

result.push_back (newmail);

}

}

void DeleteMail (const QList<int> & ids){
return counter;

}

void setTimeout (int val){
int DeleteMail (const QList<int> & ids) override{
return 0;
}

void setTimeout (int val) override{
_session->socket ().setReceiveTimeout (val);
_session->socket ().setSendTimeout (val);
}

int getTimeout (){
int getTimeout () override{
return _session->socket ().getReceiveTimeout ().totalMilliseconds ();
}

Expand All @@ -102,6 +127,9 @@ class IMAPClient : public ReceiveMailClient

private:


Poco::Net::IMAPClientSession::MessageInfoVec _mailList;

SESSION_PTR _session;

};
Expand Down
22 changes: 14 additions & 8 deletions Model/IMAPClientSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,9 @@ namespace Poco {
NumberFormatter::append0(tag, _tag++, 10);

_socket.sendMessage(tag + " " + command);

#ifdef _DEBUG
std::cout << tag + " " + command << std::endl;

#endif
while (true) {
_socket.receiveMessage(response);
if (response.substr(0, tag.length()+1) != (tag+" ")) {
Expand Down Expand Up @@ -228,7 +228,7 @@ namespace Poco {

if (!sendCommand(oss.str(), response, data)) throw NetException("Cannot fetch messages", response);

sendCommand("CLOSE", response2, data2);
// sendCommand("CLOSE", response2, data2);

for (int j = 0; j < data.size(); j++)
{
Expand Down Expand Up @@ -326,13 +326,15 @@ namespace Poco {

loadText (info.uid, info.parts, "", message);

sendCommand ("CLOSE", response, data1);
// sendCommand ("CLOSE", response, data1);

if ( data.size ( ) <= 2 ) return;

for ( int i = 1; i < data.size ( ) - 2; i++ ) {
message += data[i];
message += "\r\n";
if( data[i].length() > 0 && data[i][0] != '*' ){
message += data[i];
message += "\r\n";
}
}
}

Expand Down Expand Up @@ -369,7 +371,11 @@ namespace Poco {
}

} else {
std::cout << "UNKNONW CONTENT TRANSFER TYPE" << std::endl;
std::cout << "UNKNONW CONTENT TRANSFER TYPE: " ;
for(auto s : attrs){
std::cout << s << ";";
}
std::cout << std::endl;
text += ss.str ( );
//throw NetException ("UNKNOWN CONTENT TRANSFER TYPE");
}
Expand Down Expand Up @@ -408,7 +414,7 @@ namespace Poco {
if (!sendCommand(oss.str(), response, data)) throw NetException("Cannot fetch messages", response);

response1.clear(); data1.clear();
if (!sendCommand("CLOSE", response1, data1)) throw NetException("Cannot close folder", response);
// if (!sendCommand("CLOSE", response1, data1)) throw NetException("Cannot close folder", response);

for (int j = 0; j < data.size(); j++)
{
Expand Down
15 changes: 10 additions & 5 deletions Model/MailBody.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include<QSharedPointer>
#include<QDebug>

#include <iostream>
#include <string>


Expand All @@ -24,7 +25,7 @@ class MailBody : public QObject {

Q_PROPERTY(QString sender READ getSender CONSTANT)

Q_PROPERTY(QDateTime datetime READ getDateTime CONSTANT)
Q_PROPERTY(QString datetime READ getDateTime CONSTANT)

Q_PROPERTY(bool isread READ getIsread WRITE setIsread CONSTANT)

Expand Down Expand Up @@ -63,10 +64,15 @@ class MailBody : public QObject {
_sender = s;
}

QDateTime getDateTime(){
QString getDateTime(){
return _datetime;
}

void setDateTime(QString val){
_datetime = val;
// _datetime = QDateTime::fromString (val, Qt::RFC2822Date);
}

bool getIsread(){
return _isread;
}
Expand All @@ -79,8 +85,7 @@ class MailBody : public QObject {
return _recipients;
}

void addRecipient(QString r)
{
void addRecipient(QString r) {
_recipients.push_back (r);
}

Expand All @@ -96,7 +101,7 @@ class MailBody : public QObject {

QString _sender;

QDateTime _datetime;
QString _datetime;

QList<QString> _recipients;

Expand Down
Loading

0 comments on commit 84045c3

Please sign in to comment.