mapiTextPart.h 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. /*
  2. * Copyright 2005 - 2016 Zarafa and its licensors
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU Affero General Public License, version 3,
  6. * as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU Affero General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU Affero General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. *
  16. */
  17. // based on htmlTextPart, but with additions
  18. // we cannot use a class derived from htmlTextPart, since that class has alot of privates
  19. //
  20. // VMime library (http://www.vmime.org)
  21. // Copyright (C) 2002-2009 Vincent Richard <vincent@vincent-richard.net>
  22. //
  23. // This program is free software; you can redistribute it and/or
  24. // modify it under the terms of the GNU General Public License as
  25. // published by the Free Software Foundation; either version 3 of
  26. // the License, or (at your option) any later version.
  27. //
  28. // This program is distributed in the hope that it will be useful,
  29. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  30. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  31. // General Public License for more details.
  32. //
  33. // You should have received a copy of the GNU General Public License along
  34. // with this program; if not, write to the Free Software Foundation, Inc.,
  35. // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  36. //
  37. // Linking this library statically or dynamically with other modules is making
  38. // a combined work based on this library. Thus, the terms and conditions of
  39. // the GNU General Public License cover the whole combination.
  40. //
  41. #ifndef VMIME_MAPITEXTPART_HPP_INCLUDED
  42. #define VMIME_MAPITEXTPART_HPP_INCLUDED
  43. #include <kopano/zcdefs.h>
  44. #include <memory>
  45. #include <vmime/textPart.hpp>
  46. #include <vmime/messageId.hpp>
  47. #include <vmime/encoding.hpp>
  48. #include <vmime/contentHandler.hpp>
  49. namespace vmime {
  50. /** Text part of type 'text/html'.
  51. */
  52. class mapiTextPart _kc_final : public textPart {
  53. public:
  54. mapiTextPart();
  55. const mediaType getType(void) const _kc_override;
  56. const charset &getCharset(void) const _kc_override { return m_charset; }
  57. void setCharset(const charset &ch) _kc_override;
  58. /* plain text */
  59. vmime::shared_ptr<const contentHandler> getPlainText(void) const { return m_plainText; }
  60. void setPlainText(vmime::shared_ptr<contentHandler> plainText);
  61. /* 'other' text */
  62. vmime::shared_ptr<const contentHandler> getOtherText(void) const { return m_otherText; }
  63. void setOtherText(vmime::shared_ptr<contentHandler> otherText);
  64. /* extra 'other' properties */
  65. void setOtherContentType(const mediaType& type);
  66. void setOtherContentEncoding(const encoding& enc);
  67. void setOtherMethod(const string& method);
  68. void setOtherCharset(const charset& ch);
  69. /* html + plain + 'other' text */
  70. const vmime::shared_ptr<const contentHandler> getText(void) const _kc_override { return m_text; }
  71. void setText(vmime::shared_ptr<contentHandler> text) _kc_override;
  72. /** Embedded object (eg: image for &lt;IMG> tag).
  73. */
  74. class embeddedObject _kc_final : public object {
  75. public:
  76. embeddedObject(vmime::shared_ptr<contentHandler> data, const encoding &enc, const string &id, const mediaType &type, const string &name, const string &loc);
  77. /** Return data stored in this embedded object.
  78. *
  79. * @return stored data
  80. */
  81. vmime::shared_ptr<const contentHandler> getData(void) const { return m_data; }
  82. /** Return the encoding used for data in this
  83. * embedded object.
  84. *
  85. * @return data encoding
  86. */
  87. const vmime::encoding &getEncoding(void) const { return m_encoding; }
  88. /** Return the identifier of this embedded object.
  89. *
  90. * @return object identifier
  91. */
  92. const std::string &getId(void) const { return m_id; }
  93. /** Return the location (URL) of this embedded object.
  94. *
  95. * @return object location url
  96. */
  97. const std::string &getLocation(void) const { return m_loc; }
  98. /** Return the content type of data stored in
  99. * this embedded object.
  100. *
  101. * @return data type
  102. */
  103. const mediaType &getType(void) const { return m_type; }
  104. /** Return the object name of this embedded object, if any
  105. *
  106. * @return object name
  107. */
  108. const std::string &getName(void) const { return m_name; }
  109. private:
  110. vmime::shared_ptr<contentHandler> m_data;
  111. encoding m_encoding;
  112. string m_id;
  113. mediaType m_type;
  114. string m_name;
  115. string m_loc;
  116. };
  117. /** Test the existence of an embedded object given its identifier.
  118. *
  119. * @param id object identifier
  120. * @return true if an object with this identifier exists,
  121. * false otherwise
  122. */
  123. bool hasObject(const string& id) const;
  124. /** Return the embedded object with the specified identifier.
  125. *
  126. * @throw exceptions::no_object_found() if no object has been found
  127. * @param id object identifier
  128. * @return embedded object with the specified identifier
  129. */
  130. vmime::shared_ptr<const embeddedObject> findObject(const string &id) const;
  131. /** Return the number of embedded objects.
  132. *
  133. * @return number of embedded objects
  134. */
  135. int getObjectCount(void) const { return m_objects.size(); }
  136. /** Return the embedded object at the specified position.
  137. *
  138. * @param pos position of the embedded object
  139. * @return embedded object at position 'pos'
  140. */
  141. vmime::shared_ptr<const embeddedObject> getObjectAt(int pos) const { return m_objects[pos]; }
  142. /** Embed an object and returns a string which identifies it.
  143. * The returned identifier is suitable for use in the 'src' attribute
  144. * of an <img> tag.
  145. *
  146. * \deprecated Use the addObject() methods which take a 'contentHandler'
  147. * parameter type instead.
  148. *
  149. * @param data object data
  150. * @param type data type
  151. * @return an unique object identifier used to identify the new
  152. * object among all other embedded objects
  153. */
  154. const string addObject(const string& data, const mediaType& type);
  155. /** Embed an object and returns a string which identifies it.
  156. * The returned identifier is suitable for use in the 'src' attribute
  157. * of an <img> tag.
  158. *
  159. * @param data object data
  160. * @param type data type
  161. * @return an unique object identifier used to identify the new
  162. * object among all other embedded objects
  163. */
  164. const string addObject(vmime::shared_ptr<contentHandler> data, const mediaType &type);
  165. /** Embed an object and returns a string which identifies it.
  166. * The returned identifier is suitable for use in the 'src' attribute
  167. * of an <img> tag.
  168. *
  169. * @param data object data
  170. * @param enc data encoding
  171. * @param type data type
  172. * @return an unique object identifier used to identify the new
  173. * object among all other embedded objects
  174. */
  175. const string addObject(vmime::shared_ptr<contentHandler> data, const encoding &enc, const mediaType &type);
  176. /** Embed an object and returns a string which identifies it.
  177. *
  178. * @param data object data
  179. * @param enc data encoding
  180. * @param type data type
  181. * @param id unique object identifier
  182. * @param loc optional location url of object
  183. * @param name filename of attachment
  184. * @return an unique object identifier used to identify the new
  185. * object among all other embedded objects
  186. */
  187. const string addObject(vmime::shared_ptr<contentHandler> data, const encoding &enc, const mediaType &type, const string &id, const string &name = string(), const string &loc = string());
  188. size_t getPartCount() const _kc_override;
  189. void generateIn(vmime::shared_ptr<bodyPart> message, vmime::shared_ptr<bodyPart> parent) const _kc_override;
  190. void parse(vmime::shared_ptr<const bodyPart> message, vmime::shared_ptr<const bodyPart> parent, vmime::shared_ptr<const bodyPart> textPart) _kc_override;
  191. private:
  192. vmime::shared_ptr<contentHandler> m_plainText;
  193. vmime::shared_ptr<contentHandler> m_text; /* htmlText */
  194. charset m_charset;
  195. vmime::shared_ptr<contentHandler> m_otherText;
  196. mediaType m_otherMediaType;
  197. encoding m_otherEncoding;
  198. string m_otherMethod; /* ical special */
  199. charset m_otherCharset;
  200. bool m_bHaveOtherCharset;
  201. std::vector<vmime::shared_ptr<embeddedObject> > m_objects;
  202. void findEmbeddedParts(const bodyPart& part, std::vector<vmime::shared_ptr<const bodyPart> > &cidParts, std::vector<vmime::shared_ptr<const bodyPart> > &locParts);
  203. void addEmbeddedObject(const bodyPart& part, const string& id);
  204. bool findPlainTextPart(const bodyPart& part, const bodyPart& parent, const bodyPart& textPart);
  205. static const string cleanId(const string& id);
  206. };
  207. } // vmime
  208. #endif // VMIME_HTMLTEXTPART_HPP_INCLUDED