From 60ccf9b246904b6efa4f96ea8075fe8f67faa940 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Lanzend=C3=B6rfer?= Date: Sat, 25 Dec 2021 21:53:37 +0000 Subject: [PATCH] Viewer plugin --- messageviewerplugin/CMakeLists.txt | 2 +- messageviewerplugin/pephelpers.cpp | 142 ------------------ .../viewerpluginpepinterface.cpp | 45 +++--- .../viewerpluginpepinterface.h | 7 - 4 files changed, 19 insertions(+), 177 deletions(-) delete mode 100644 messageviewerplugin/pephelpers.cpp diff --git a/messageviewerplugin/CMakeLists.txt b/messageviewerplugin/CMakeLists.txt index 95149d0..1d498c7 100644 --- a/messageviewerplugin/CMakeLists.txt +++ b/messageviewerplugin/CMakeLists.txt @@ -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 diff --git a/messageviewerplugin/pephelpers.cpp b/messageviewerplugin/pephelpers.cpp deleted file mode 100644 index c5032f0..0000000 --- a/messageviewerplugin/pephelpers.cpp +++ /dev/null @@ -1,142 +0,0 @@ -#include "viewerpluginpepinterface.h" - -#include -#include -#include -#include - -#include -#include -#include - -#include - -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 -} - diff --git a/messageviewerplugin/viewerpluginpepinterface.cpp b/messageviewerplugin/viewerpluginpepinterface.cpp index d1aa347..e929346 100644 --- a/messageviewerplugin/viewerpluginpepinterface.cpp +++ b/messageviewerplugin/viewerpluginpepinterface.cpp @@ -21,14 +21,17 @@ #include #include -#include -#include #include #include #include -#include +#include +#include +#include + +// glue code for conversion +#include // The pEp engine #include @@ -62,27 +65,6 @@ QList 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")) { - } + }*/ } } diff --git a/messageviewerplugin/viewerpluginpepinterface.h b/messageviewerplugin/viewerpluginpepinterface.h index 5b03f2c..47668c6 100644 --- a/messageviewerplugin/viewerpluginpepinterface.h +++ b/messageviewerplugin/viewerpluginpepinterface.h @@ -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 mAction;