EightBitMimeHandler.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. /*
  3. * This file is part of SwiftMailer.
  4. * (c) 2018 Christian Schmidt
  5. *
  6. * For the full copyright and license information, please view the LICENSE
  7. * file that was distributed with this source code.
  8. */
  9. /**
  10. * An ESMTP handler for 8BITMIME support (RFC 6152).
  11. *
  12. * 8BITMIME is required when sending 8-bit content to over SMTP, e.g. when using
  13. * Swift_Mime_ContentEncoder_PlainContentEncoder in "8bit" mode.
  14. *
  15. * 8BITMIME mode is enabled unconditionally, even when sending ASCII-only
  16. * messages, so it should only be used with an outbound SMTP server that will
  17. * convert the message to 7-bit MIME if the next hop does not support 8BITMIME.
  18. *
  19. * @author Christian Schmidt
  20. */
  21. class Swift_Transport_Esmtp_EightBitMimeHandler implements Swift_Transport_EsmtpHandler
  22. {
  23. protected $encoding;
  24. /**
  25. * @param string $encoding The parameter so send with the MAIL FROM command;
  26. * either "8BITMIME" or "7BIT"
  27. */
  28. public function __construct(string $encoding = '8BITMIME')
  29. {
  30. $this->encoding = $encoding;
  31. }
  32. /**
  33. * Get the name of the ESMTP extension this handles.
  34. *
  35. * @return string
  36. */
  37. public function getHandledKeyword()
  38. {
  39. return '8BITMIME';
  40. }
  41. /**
  42. * Not used.
  43. */
  44. public function setKeywordParams(array $parameters)
  45. {
  46. }
  47. /**
  48. * Not used.
  49. */
  50. public function afterEhlo(Swift_Transport_SmtpAgent $agent)
  51. {
  52. }
  53. /**
  54. * Get params which are appended to MAIL FROM:<>.
  55. *
  56. * @return string[]
  57. */
  58. public function getMailParams()
  59. {
  60. return ['BODY='.$this->encoding];
  61. }
  62. /**
  63. * Not used.
  64. */
  65. public function getRcptParams()
  66. {
  67. return [];
  68. }
  69. /**
  70. * Not used.
  71. */
  72. public function onCommand(Swift_Transport_SmtpAgent $agent, $command, $codes = [], &$failedRecipients = null, &$stop = false)
  73. {
  74. }
  75. /**
  76. * Returns +1, -1 or 0 according to the rules for usort().
  77. *
  78. * This method is called to ensure extensions can be execute in an appropriate order.
  79. *
  80. * @param string $esmtpKeyword to compare with
  81. *
  82. * @return int
  83. */
  84. public function getPriorityOver($esmtpKeyword)
  85. {
  86. return 0;
  87. }
  88. /**
  89. * Not used.
  90. */
  91. public function exposeMixinMethods()
  92. {
  93. return [];
  94. }
  95. /**
  96. * Not used.
  97. */
  98. public function resetState()
  99. {
  100. }
  101. }