KDE PIM support for the p≡p engine
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

129 lines
4.4 KiB

  1. #include "pephelpers.h"
  2. KMime::Message::Ptr pEpKDE::to_mMessage(message *m)
  3. {
  4. KMime::Message::Ptr mMessage;
  5. if(!m) {
  6. return mMessage;
  7. }
  8. mMessage->from()->from7BitString( QByteArray(m->from->address) );
  9. mMessage->to()->from7BitString( QByteArray(m->to->ident->address) );
  10. foreach ( KMime::Content *attachment, mMessage->contents() ) {
  11. attachment->setContent(QByteArray("pEp"));
  12. attachment->contentType()->setMimeType(QByteArray("text/plain"));
  13. }
  14. return mMessage;
  15. }
  16. void pEpKDE::mboxlist_to_message(KMime::Types::Mailbox::List mboxlist, identity_list* peplist)
  17. {
  18. KMime::Types::Mailbox mbox;
  19. foreach ( mbox, mboxlist ) {
  20. peplist = identity_list_add(peplist,
  21. new_identity(
  22. mbox.address().data(),
  23. "",
  24. mbox.address().split('@').at(0).data(),
  25. mbox.name().toLatin1().data()
  26. )
  27. );
  28. }
  29. }
  30. message* pEpKDE::to_pEpMessage(KMime::Message::Ptr mMessage, PEP_msg_direction direction)
  31. {
  32. KMime::Types::Mailbox mbox;
  33. if(!mMessage)
  34. return NULL;
  35. message *m = new_message(direction);
  36. if(!m)
  37. return NULL;
  38. m->longmsg = mMessage->decodedContent().data(),
  39. m->longmsg_formatted = mMessage->decodedContent().data(),
  40. mbox = mMessage->from()->mailboxes().at(0);
  41. m->from = new_identity(
  42. mbox.address().data(),
  43. "",
  44. mbox.address().split('@').at(0).data(),
  45. mbox.name().toLatin1().data()
  46. );
  47. mboxlist_to_message( mMessage->to()->mailboxes(), m->to );
  48. mboxlist_to_message( mMessage->cc()->mailboxes(), m->cc );
  49. mboxlist_to_message( mMessage->bcc()->mailboxes(), m->bcc );
  50. mboxlist_to_message( mMessage->replyTo()->mailboxes(), m->reply_to );
  51. foreach ( KMime::Content *attachment, mMessage->contents() ) {
  52. m->attachments = bloblist_add(
  53. m->attachments,
  54. attachment->decodedContent().data(),
  55. attachment->size(),
  56. attachment->contentType()->mimeType().data(),
  57. MimeTreeParser::NodeHelper::fileName(attachment).toLatin1().data()
  58. );
  59. }
  60. return m;
  61. #if 0
  62. m.id=""; // UTF-8 string of message ID
  63. m.shortmsg=""; // UTF-8 string of short message
  64. m.longmsg=""; // UTF-8 string of long message (plain)
  65. m.longmsg_formatted=""; // UTF-8 string of long message (formatted)
  66. bloblist_t attachments;
  67. m.attachments=&attachments; // blobs with attachements
  68. m.rawmsg_ref=""; // reference to raw message data
  69. m.rawmsg_size=0; // size of raw message data
  70. timestamp sent;
  71. m.sent=&sent; // when the message is sent
  72. timestamp recv;
  73. m.recv=&recv; // when the message is received
  74. pEp_identity from;
  75. m.from=&from; // whom the message is from
  76. identity_list to;
  77. m.to=&to; // whom the message is to
  78. pEp_identity recv_by;
  79. m.recv_by=&recv_by; // via which identity the message is received
  80. identity_list cc;
  81. m.cc=&cc; // whom a CC is being sent
  82. identity_list bcc;
  83. m.bcc=&bcc; // whom a BCC is being sent
  84. identity_list reply_to;
  85. m.reply_to=&reply_to; // where a reply should go to
  86. stringlist_t in_reply_to;
  87. m.in_reply_to=&in_reply_to; // list of UTF-8 strings with MessageIDs of refering messages
  88. /*
  89. struct _message *refering_msg_ref; // reference to refering message
  90. stringlist_t *references; // list of UTF-8 strings with references
  91. struct _message_ref_list *refered_by; // list of references to messages being
  92. // refered
  93. stringlist_t *keywords; // list of UTF-8 strings with keywords
  94. char *comments; // UTF-8 string with comments
  95. stringpair_list_t *opt_fields; // optional fields
  96. PEP_enc_format enc_format; // format of encrypted data
  97. char* _sender_fpr; // INTERNAL USE ONLY - fingerprint of
  98. // sending signer.
  99. // (read_only to the outside)
  100. */
  101. #endif
  102. }