| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
#ifndef MSGPARTREPLY_H |
| 19 |
#define MSGPARTREPLY_H |
| 20 |
|
| 21 |
#include <QObject> |
| 22 |
#include <QBuffer> |
| 23 |
#include <QNetworkReply> |
| 24 |
#include <qmailstore.h> |
| 25 |
#include <qmailmessage.h> |
| 26 |
#include <MailServiceClient.h> |
| 27 |
#include "MsgPartQNAM.h" |
| 28 |
|
| 29 |
struct PartFinder { |
| 30 |
QString location; |
| 31 |
const QMailMessagePart *part; |
| 32 |
PartFinder() {} |
| 33 |
PartFinder(const QString &location) : location(location) {} |
| 34 |
|
| 35 |
bool operator()(const QMailMessagePart &p) { |
| 36 |
const bool isPart = (p.location().toString(true) == location); |
| 37 |
if (isPart) { |
| 38 |
part = const_cast<QMailMessagePart *>(&p); |
| 39 |
} |
| 40 |
return !isPart; |
| 41 |
} |
| 42 |
}; |
| 43 |
|
| 44 |
struct CidPartDetector { |
| 45 |
QString cid; |
| 46 |
QString location; |
| 47 |
|
| 48 |
CidPartDetector(const QString &cid) : cid(cid) {} |
| 49 |
|
| 50 |
bool operator()(const QMailMessagePart &part) { |
| 51 |
const bool isPart = (part.contentID() == QUrl(cid).path()); |
| 52 |
if (isPart) { |
| 53 |
location = part.location().toString(true); |
| 54 |
} |
| 55 |
return !isPart; |
| 56 |
} |
| 57 |
}; |
| 58 |
|
| 59 |
class MsgPartReply : public QNetworkReply |
| 60 |
{ |
| 61 |
Q_OBJECT |
| 62 |
public: |
| 63 |
MsgPartReply(MsgPartQNAM *parent, const QMailMessageId &id, const QString &cidUrl); |
| 64 |
MsgPartReply(MsgPartQNAM *parent, const QMailMessageId &id, const QString &location, |
| 65 |
const bool plaintext, const bool requiresFormatting); |
| 66 |
~MsgPartReply(); |
| 67 |
|
| 68 |
|
| 69 |
public: |
| 70 |
virtual void close(); |
| 71 |
virtual qint64 bytesAvailable() const; |
| 72 |
|
| 73 |
protected: |
| 74 |
virtual qint64 readData(char *data, qint64 maxlen); |
| 75 |
void failed(const QString &reason); |
| 76 |
const QMailMessagePart *partPtr( const bool refresh = false); |
| 77 |
|
| 78 |
|
| 79 |
public slots: |
| 80 |
virtual void abort() { close(); } |
| 81 |
|
| 82 |
void handleMsgPartAvailable(const quint64 &id, const QString &location); |
| 83 |
void handlePartFetchFailed(const quint64 &id, const QString &location); |
| 84 |
|
| 85 |
void messageReady(); |
| 86 |
void init(); |
| 87 |
protected: |
| 88 |
bool cidToPart(const QMailMessage &message, const QString &cidUrl); |
| 89 |
private: |
| 90 |
|
| 91 |
class Part { |
| 92 |
public: |
| 93 |
Part(const QMailMessageId &id, const QString &location) : m_finder(0), m_msg(id) { |
| 94 |
m_finder = PartFinder(location); |
| 95 |
m_msg.foreachPart<PartFinder &>(m_finder); |
| 96 |
} |
| 97 |
const QMailMessage parentMessage() { |
| 98 |
return m_msg; |
| 99 |
} |
| 100 |
|
| 101 |
const QMailMessagePart *partPtr() { |
| 102 |
return m_finder.part; |
| 103 |
} |
| 104 |
private: |
| 105 |
PartFinder m_finder; |
| 106 |
QMailMessage m_msg; |
| 107 |
}; |
| 108 |
|
| 109 |
QByteArray *formattedBufferContent; |
| 110 |
QByteArray *secondBuffer; |
| 111 |
mutable QBuffer buffer; |
| 112 |
QMailMessageId m_msgId; |
| 113 |
QString m_location; |
| 114 |
bool m_ptext; |
| 115 |
bool m_format; |
| 116 |
Part *m_part; |
| 117 |
}; |
| 118 |
|
| 119 |
#endif |