mapiAttachment.cpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. #include <memory>
  18. #include "mapiAttachment.h"
  19. #include <vmime/contentDispositionField.hpp>
  20. #include <vmime/contentTypeField.hpp>
  21. #include <vmime/messageId.hpp>
  22. namespace KC {
  23. mapiAttachment::mapiAttachment(vmime::shared_ptr<const vmime::contentHandler> data,
  24. const vmime::encoding &enc, const vmime::mediaType &type,
  25. const std::string &contentid, const vmime::word filename,
  26. const vmime::text &desc, const vmime::word &name) :
  27. defaultAttachment(data, enc, type, desc, name)
  28. {
  29. m_filename = filename;
  30. m_contentid = contentid;
  31. m_hasCharset = false;
  32. }
  33. void mapiAttachment::addCharset(vmime::charset ch) {
  34. m_hasCharset = true;
  35. m_charset = ch;
  36. }
  37. void mapiAttachment::generatePart(vmime::shared_ptr<vmime::bodyPart> part) const
  38. {
  39. vmime::defaultAttachment::generatePart(part);
  40. vmime::dynamicCast<vmime::contentDispositionField>(part->getHeader()->ContentDisposition())->setFilename(m_filename);
  41. auto ctf = vmime::dynamicCast<vmime::contentTypeField>(part->getHeader()->ContentType());
  42. ctf->getParameter("name")->setValue(m_filename);
  43. if (m_hasCharset)
  44. ctf->setCharset(vmime::charset(m_charset));
  45. if (m_contentid != "") {
  46. // Field is created when accessed through ContentId, so don't create if we have no
  47. // content-id to set
  48. part->getHeader()->ContentId()->setValue(vmime::messageId("<" + m_contentid + ">"));
  49. }
  50. }
  51. } /* namespace */