IMAPClient.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*
  2. * @file IMAPClient.h
  3. * @brief libcurl wrapper for IMAP operations
  4. *
  5. * @author Mohamed Amine Mzoughi <mohamed-amine.mzoughi@laposte.net>
  6. * @date 2017-01-02
  7. *
  8. * Updated by acetone in 2023
  9. */
  10. #ifndef INCLUDE_IMAPCLIENT_H_
  11. #define INCLUDE_IMAPCLIENT_H_
  12. #include "MAILClient.h"
  13. class CIMAPClient : public CMailClient
  14. {
  15. public:
  16. enum class MailProperty
  17. {
  18. Deleted,
  19. Seen,
  20. Answered,
  21. Flagged,
  22. Draft,
  23. Recent
  24. };
  25. enum class SearchOption
  26. {
  27. ANSWERED,
  28. DELETED,
  29. DRAFT,
  30. FLAGGED,
  31. NEW,
  32. RECENT,
  33. SEEN,
  34. UNSEEN
  35. };
  36. explicit CIMAPClient(LogFnCallback oLogger);
  37. // copy constructor and assignment operator are disabled
  38. CIMAPClient(const CIMAPClient& Copy) = delete;
  39. CIMAPClient& operator=(const CIMAPClient& Copy) = delete;
  40. bool CleanupSession() override;
  41. /* list the folders within a mailbox and save it in strList */
  42. bool List(std::string& strList, const std::string& strFolderName = "");
  43. /* list the subscribed folders and save it in strList */
  44. bool ListSubFolders(std::string& strList);
  45. /* send a string as an e-mail */
  46. bool SendString(const std::string& strMail);
  47. /* send a text file as an e-mail */
  48. bool SendFile(const std::string& strPath);
  49. /* retrieve e-mail and save its content in strOutput */
  50. bool GetString(const std::string& strMsgNumber, std::string& strOutput);
  51. /* retrieve e-mail and save its content in a file */
  52. bool GetFile(const std::string& strMsgNumber, const std::string& strFilePath);
  53. /* delete an existing folder */
  54. bool DeleteFolder(const std::string& strMsgNumber);
  55. /* perform a noop */
  56. bool Noop();
  57. /* copy an e-mail from one folder to another */
  58. bool CopyMail(const std::string& strMsgNumber, const std::string& strFolder);
  59. /* create a new folder */
  60. bool CreateFolder(const std::string& strFolderName);
  61. /* modify the properties of an e-mail according to MailProperty */
  62. bool SetMailProperty(const std::string& strMsgNumber, MailProperty eNewProperty);
  63. /* search for e-mails according to SearchOption */
  64. bool Search(std::string& strRes, SearchOption eSearchOption = SearchOption::NEW);
  65. /* obtain information about a folder */
  66. bool InfoFolder(std::string& strFolderName, std::string& strInfo);
  67. protected:
  68. enum MailOperation
  69. {
  70. IMAP_NOOP,
  71. IMAP_LIST,
  72. IMAP_SEND_STRING,
  73. IMAP_SEND_FILE,
  74. IMAP_RETR_FILE,
  75. IMAP_RETR_STRING,
  76. IMAP_DELETE_FOLDER,
  77. IMAP_INFO_FOLDER,
  78. IMAP_LSUB,
  79. IMAP_COPY,
  80. IMAP_CREATE,
  81. IMAP_SEARCH,
  82. IMAP_STORE
  83. };
  84. bool PrePerform() override;
  85. bool PostPerform(CURLcode ePerformCode) override;
  86. inline void ParseURL(std::string& strURL) override final;
  87. MailOperation m_eOperationType;
  88. MailProperty m_eMailProperty;
  89. SearchOption m_eSearchOption;
  90. std::string m_strFrom;
  91. std::string m_strTo;
  92. std::string m_strCc;
  93. std::string m_strMail;
  94. std::string m_strMsgNumber;
  95. std::string m_strFolderName;
  96. std::string* m_pstrText;
  97. };
  98. #endif