Viewer plugin

master
David Lanzendörfer 1 year ago
parent 95e32f0225
commit 60ccf9b246

@ -1,7 +1,7 @@
set(messageviewer_pepplugin_SRCS
viewerpluginpep.cpp
viewerpluginpepinterface.cpp
pephelpers.cpp
../kde_pep_common/pephelpers.cpp
)
ecm_qt_declare_logging_category(messageviewer_pepplugin_SRCS HEADER pepplugin_debug.h IDENTIFIER CREATENOTEPLUGIN_LOG CATEGORY_NAME org.kde.pim.pepplugin

@ -1,142 +0,0 @@
#include "viewerpluginpepinterface.h"
#include <MimeTreeParser/NodeHelper>
#include <KMime/Headers>
#include <KMime/Types>
#include <KMime/HeaderParsing>
#include <QStringLiteral>
#include <QByteArray>
#include <QRegularExpression>
#include <pEp/message.h>
using namespace MessageViewer;
KMime::Message::Ptr pEpViewerInterface::to_mMessage(message *m)
{
KMime::Message::Ptr mMessage;
if(!m) {
return mMessage;
}
mMessage->from()->from7BitString( QByteArray(m->from->address) );
mMessage->to()->from7BitString( QByteArray(m->to->ident->address) );
foreach ( KMime::Content *attachment, mMessage->contents() ) {
attachment->setContent(QByteArray("pEp"));
attachment->contentType()->setMimeType(QByteArray("text/plain"));
}
return mMessage;
}
void pEpViewerInterface::mboxlist_to_message(KMime::Types::Mailbox::List mboxlist, identity_list* peplist)
{
KMime::Types::Mailbox mbox;
foreach ( mbox, mboxlist ) {
peplist = identity_list_add(peplist,
new_identity(
mbox.address().data(),
"",
mbox.address().split('@').at(0).data(),
mbox.name().toLatin1().data()
)
);
}
}
message* pEpViewerInterface::to_pEpMessage(KMime::Message::Ptr mMessage, PEP_msg_direction direction)
{
KMime::Types::Mailbox mbox;
if(!mMessage)
return NULL;
message *m = new_message(direction);
if(!m)
return NULL;
m->longmsg = mMessage->decodedContent().data(),
m->longmsg_formatted = mMessage->decodedContent().data(),
mbox = mMessage->from()->mailboxes().at(0);
m->from = new_identity(
mbox.address().data(),
"",
mbox.address().split('@').at(0).data(),
mbox.name().toLatin1().data()
);
mboxlist_to_message( mMessage->to()->mailboxes(), m->to );
mboxlist_to_message( mMessage->cc()->mailboxes(), m->cc );
mboxlist_to_message( mMessage->bcc()->mailboxes(), m->bcc );
mboxlist_to_message( mMessage->replyTo()->mailboxes(), m->reply_to );
foreach ( KMime::Content *attachment, mMessage->contents() ) {
m->attachments = bloblist_add(
m->attachments,
attachment->decodedContent().data(),
attachment->size(),
attachment->contentType()->mimeType().data(),
MimeTreeParser::NodeHelper::fileName(attachment).toLatin1().data()
);
}
return m;
#if 0
m.id=""; // UTF-8 string of message ID
m.shortmsg=""; // UTF-8 string of short message
m.longmsg=""; // UTF-8 string of long message (plain)
m.longmsg_formatted=""; // UTF-8 string of long message (formatted)
bloblist_t attachments;
m.attachments=&attachments; // blobs with attachements
m.rawmsg_ref=""; // reference to raw message data
m.rawmsg_size=0; // size of raw message data
timestamp sent;
m.sent=&sent; // when the message is sent
timestamp recv;
m.recv=&recv; // when the message is received
pEp_identity from;
m.from=&from; // whom the message is from
identity_list to;
m.to=&to; // whom the message is to
pEp_identity recv_by;
m.recv_by=&recv_by; // via which identity the message is received
identity_list cc;
m.cc=&cc; // whom a CC is being sent
identity_list bcc;
m.bcc=&bcc; // whom a BCC is being sent
identity_list reply_to;
m.reply_to=&reply_to; // where a reply should go to
stringlist_t in_reply_to;
m.in_reply_to=&in_reply_to; // list of UTF-8 strings with MessageIDs of refering messages
/*
struct _message *refering_msg_ref; // reference to refering message
stringlist_t *references; // list of UTF-8 strings with references
struct _message_ref_list *refered_by; // list of references to messages being
// refered
stringlist_t *keywords; // list of UTF-8 strings with keywords
char *comments; // UTF-8 string with comments
stringpair_list_t *opt_fields; // optional fields
PEP_enc_format enc_format; // format of encrypted data
char* _sender_fpr; // INTERNAL USE ONLY - fingerprint of
// sending signer.
// (read_only to the outside)
*/
#endif
}

@ -21,14 +21,17 @@
#include <QByteArray>
#include <QVariantList>
#include <ItemFetchJob>
#include <ItemFetchScope>
#include <MessageViewer/CSSHelper>
#include <KontactInterface/Core>
#include <KontactInterface/PimUniqueApplication>
#include <AkonadiCore/ServerManager>
#include <Akonadi/ItemFetchJob>
#include <Akonadi/ItemFetchScope>
#include <Akonadi/ServerManager>
// glue code for conversion
#include <kde_pep_common/pephelpers.h>
// The pEp engine
#include <pEp/mime.h>
@ -62,27 +65,6 @@ QList<QAction *> pEpViewerInterface::actions() const
return mAction;
}
bool pEpViewerInterface::isApEpMessage(KMime::Content *content)
{
if(!content)
return false;
if(content->attachments().size()) {
qDebug() << __FUNCTION__ << "Has attachments";
for(KMime::Content *c : content->attachments()) {
//if(isApEpMessage(c)) return true;
isApEpMessage(c);
}
} else {
//qDebug() << content->decodedContent();
}
qDebug() << __FUNCTION__ << "Not a pEp message";
//qDebug() << content->contentType()->name();
return false;
}
void pEpViewerInterface::setMessage(const KMime::Message::Ptr &value)
{
message *m;
@ -91,8 +73,17 @@ void pEpViewerInterface::setMessage(const KMime::Message::Ptr &value)
char *ms;
if(value) {
type = value->contentType()->mimeType();
qDebug() << type;
if(type.contains("encrypted")) {
if (value->subject()->asUnicodeString() == QStringLiteral("p≡p")) {
if (m_pEpClient->isValid()) {
m = pEpKDE::to_pEpMessage(value, PEP_dir_incoming);
::mime_encode_message(m, true, &ms, true);
qDebug() << "ms encoded: " << ms;
auto ret = m_pEpClient->call(QStringLiteral("decrypt_message"), QLatin1String(ms));
args = ret.arguments();
qDebug() << args;
}
}
/*if(type.contains("encrypted")) {
m = to_pEpMessage(value, PEP_dir_incoming);
::mime_encode_message(m, true, &ms, true);
if(m_pEpClient->isValid()) {
@ -101,7 +92,7 @@ void pEpViewerInterface::setMessage(const KMime::Message::Ptr &value)
qDebug() << args;
}
} else if(type.contains("multipart")) {
}
}*/
}
}

@ -40,13 +40,6 @@ public:
//Q_REQUIRED_RESULT MessageViewer::ViewerPluginInterface *createView(QWidget *parent, KActionCollection *ac);
private:
// glue between Akonadi and pEp:
message* to_pEpMessage(KMime::Message::Ptr mMessage, PEP_msg_direction direction);
KMime::Message::Ptr to_mMessage(message *m);
void mboxlist_to_message(KMime::Types::Mailbox::List mboxlist, identity_list *peplist);
bool isApEpMessage(KMime::Content *c);
QDBusInterface *m_pEpClient = nullptr;
Akonadi::Item mMessageItem;
QList<QAction *> mAction;

Loading…
Cancel
Save