emaildocumententry.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. * This file is part of QtEmailFetcher project: Email parser for C++ Qt.
  3. *
  4. * GPLv3+ (c) acetone, 2023
  5. */
  6. #pragma once
  7. #include <QString>
  8. #include <QStringList>
  9. #include <QSharedPointer>
  10. class EmailDocumentEntry
  11. {
  12. public:
  13. struct ContentType
  14. {
  15. enum Enum {
  16. undefined = 0,
  17. imagePng = 10,
  18. imageJpeg = 11,
  19. imageOther,
  20. textPlain = 20,
  21. textOther = 21,
  22. multipartAlternative = 30,
  23. multipartMixed = 31,
  24. multipartRelated = 32,
  25. multipartOther,
  26. binary = 40
  27. };
  28. Enum enumerate = Enum::undefined;
  29. QString string = "Undefined";
  30. };
  31. enum class TransferEncoding
  32. {
  33. textPlain,
  34. base64
  35. };
  36. EmailDocumentEntry(QList<QSharedPointer<EmailDocumentEntry>>* attachments = nullptr);
  37. void parse(const QByteArray& data);
  38. static ContentType contentTypeFromString(const QString& string);
  39. static ContentType contentTypeToString(ContentType type);
  40. static ContentType parseContentType(const QByteArray& data, QString* name = nullptr, QString* boundary = nullptr, QString* charset = nullptr);
  41. static TransferEncoding parseTransferEncoding(const QByteArray& data);
  42. static QString primaryLineDelimiter(const QByteArray& data);
  43. ContentType contentType() const { return m_contentType; }
  44. QByteArray content() const { return m_content; }
  45. QString name() const { return m_name; }
  46. QByteArray rawPayload() const;
  47. QByteArray rawHeaders() const;
  48. private:
  49. void multipart(QByteArray section);
  50. QByteArray m_rawData;
  51. QList<QSharedPointer<EmailDocumentEntry>>* m_pAttachments;
  52. ContentType m_contentType;
  53. QByteArray m_content;
  54. QString m_name = "Undefined";
  55. };