/core/Associates/SwiftMailer/vendor/swiftmailer/swiftmailer/tests/acceptance/Swift/Mime/SimpleMessageAcceptanceTest.php

https://gitlab.com/fiesta-framework/Documentation · PHP · 1251 lines · 1135 code · 109 blank · 7 comment · 0 complexity · e1a103a7bbaf5f18c12cca000a619aa8 MD5 · raw file

  1. <?php
  2. class Swift_Mime_SimpleMessageAcceptanceTest extends \PHPUnit_Framework_TestCase
  3. {
  4. public function setUp()
  5. {
  6. Swift_Preferences::getInstance()->setCharset(null); //TODO: Test with the charset defined
  7. }
  8. public function testBasicHeaders()
  9. {
  10. /* -- RFC 2822, 3.6.
  11. */
  12. $message = $this->_createMessage();
  13. $id = $message->getId();
  14. $date = $message->getDate();
  15. $this->assertEquals(
  16. 'Message-ID: <'.$id.'>'."\r\n".
  17. 'Date: '.date('r', $date)."\r\n".
  18. 'From: '."\r\n".
  19. 'MIME-Version: 1.0'."\r\n".
  20. 'Content-Type: text/plain'."\r\n".
  21. 'Content-Transfer-Encoding: quoted-printable'."\r\n",
  22. $message->toString(),
  23. '%s: Only required headers, and non-empty headers should be displayed'
  24. );
  25. }
  26. public function testSubjectIsDisplayedIfSet()
  27. {
  28. $message = $this->_createMessage();
  29. $message->setSubject('just a test subject');
  30. $id = $message->getId();
  31. $date = $message->getDate();
  32. $this->assertEquals(
  33. 'Message-ID: <'.$id.'>'."\r\n".
  34. 'Date: '.date('r', $date)."\r\n".
  35. 'Subject: just a test subject'."\r\n".
  36. 'From: '."\r\n".
  37. 'MIME-Version: 1.0'."\r\n".
  38. 'Content-Type: text/plain'."\r\n".
  39. 'Content-Transfer-Encoding: quoted-printable'."\r\n",
  40. $message->toString()
  41. );
  42. }
  43. public function testDateCanBeSet()
  44. {
  45. $message = $this->_createMessage();
  46. $message->setSubject('just a test subject');
  47. $id = $message->getId();
  48. $message->setDate(1234);
  49. $this->assertEquals(
  50. 'Message-ID: <'.$id.'>'."\r\n".
  51. 'Date: '.date('r', 1234)."\r\n".
  52. 'Subject: just a test subject'."\r\n".
  53. 'From: '."\r\n".
  54. 'MIME-Version: 1.0'."\r\n".
  55. 'Content-Type: text/plain'."\r\n".
  56. 'Content-Transfer-Encoding: quoted-printable'."\r\n",
  57. $message->toString()
  58. );
  59. }
  60. public function testMessageIdCanBeSet()
  61. {
  62. $message = $this->_createMessage();
  63. $message->setSubject('just a test subject');
  64. $message->setId('foo@bar');
  65. $date = $message->getDate();
  66. $this->assertEquals(
  67. 'Message-ID: <foo@bar>'."\r\n".
  68. 'Date: '.date('r', $date)."\r\n".
  69. 'Subject: just a test subject'."\r\n".
  70. 'From: '."\r\n".
  71. 'MIME-Version: 1.0'."\r\n".
  72. 'Content-Type: text/plain'."\r\n".
  73. 'Content-Transfer-Encoding: quoted-printable'."\r\n",
  74. $message->toString()
  75. );
  76. }
  77. public function testContentTypeCanBeChanged()
  78. {
  79. $message = $this->_createMessage();
  80. $message->setSubject('just a test subject');
  81. $message->setContentType('text/html');
  82. $id = $message->getId();
  83. $date = $message->getDate();
  84. $this->assertEquals(
  85. 'Message-ID: <'.$id.'>'."\r\n".
  86. 'Date: '.date('r', $date)."\r\n".
  87. 'Subject: just a test subject'."\r\n".
  88. 'From: '."\r\n".
  89. 'MIME-Version: 1.0'."\r\n".
  90. 'Content-Type: text/html'."\r\n".
  91. 'Content-Transfer-Encoding: quoted-printable'."\r\n",
  92. $message->toString()
  93. );
  94. }
  95. public function testCharsetCanBeSet()
  96. {
  97. $message = $this->_createMessage();
  98. $message->setSubject('just a test subject');
  99. $message->setContentType('text/html');
  100. $message->setCharset('iso-8859-1');
  101. $id = $message->getId();
  102. $date = $message->getDate();
  103. $this->assertEquals(
  104. 'Message-ID: <'.$id.'>'."\r\n".
  105. 'Date: '.date('r', $date)."\r\n".
  106. 'Subject: just a test subject'."\r\n".
  107. 'From: '."\r\n".
  108. 'MIME-Version: 1.0'."\r\n".
  109. 'Content-Type: text/html; charset=iso-8859-1'."\r\n".
  110. 'Content-Transfer-Encoding: quoted-printable'."\r\n",
  111. $message->toString()
  112. );
  113. }
  114. public function testFormatCanBeSet()
  115. {
  116. $message = $this->_createMessage();
  117. $message->setSubject('just a test subject');
  118. $message->setFormat('flowed');
  119. $id = $message->getId();
  120. $date = $message->getDate();
  121. $this->assertEquals(
  122. 'Message-ID: <'.$id.'>'."\r\n".
  123. 'Date: '.date('r', $date)."\r\n".
  124. 'Subject: just a test subject'."\r\n".
  125. 'From: '."\r\n".
  126. 'MIME-Version: 1.0'."\r\n".
  127. 'Content-Type: text/plain; format=flowed'."\r\n".
  128. 'Content-Transfer-Encoding: quoted-printable'."\r\n",
  129. $message->toString()
  130. );
  131. }
  132. public function testEncoderCanBeSet()
  133. {
  134. $message = $this->_createMessage();
  135. $message->setSubject('just a test subject');
  136. $message->setContentType('text/html');
  137. $message->setEncoder(
  138. new Swift_Mime_ContentEncoder_PlainContentEncoder('7bit')
  139. );
  140. $id = $message->getId();
  141. $date = $message->getDate();
  142. $this->assertEquals(
  143. 'Message-ID: <'.$id.'>'."\r\n".
  144. 'Date: '.date('r', $date)."\r\n".
  145. 'Subject: just a test subject'."\r\n".
  146. 'From: '."\r\n".
  147. 'MIME-Version: 1.0'."\r\n".
  148. 'Content-Type: text/html'."\r\n".
  149. 'Content-Transfer-Encoding: 7bit'."\r\n",
  150. $message->toString()
  151. );
  152. }
  153. public function testFromAddressCanBeSet()
  154. {
  155. $message = $this->_createMessage();
  156. $message->setSubject('just a test subject');
  157. $message->setFrom('chris.corbyn@swiftmailer.org');
  158. $id = $message->getId();
  159. $date = $message->getDate();
  160. $this->assertEquals(
  161. 'Message-ID: <'.$id.'>'."\r\n".
  162. 'Date: '.date('r', $date)."\r\n".
  163. 'Subject: just a test subject'."\r\n".
  164. 'From: chris.corbyn@swiftmailer.org'."\r\n".
  165. 'MIME-Version: 1.0'."\r\n".
  166. 'Content-Type: text/plain'."\r\n".
  167. 'Content-Transfer-Encoding: quoted-printable'."\r\n",
  168. $message->toString()
  169. );
  170. }
  171. public function testFromAddressCanBeSetWithName()
  172. {
  173. $message = $this->_createMessage();
  174. $message->setSubject('just a test subject');
  175. $message->setFrom(array('chris.corbyn@swiftmailer.org' => 'Chris Corbyn'));
  176. $id = $message->getId();
  177. $date = $message->getDate();
  178. $this->assertEquals(
  179. 'Message-ID: <'.$id.'>'."\r\n".
  180. 'Date: '.date('r', $date)."\r\n".
  181. 'Subject: just a test subject'."\r\n".
  182. 'From: Chris Corbyn <chris.corbyn@swiftmailer.org>'."\r\n".
  183. 'MIME-Version: 1.0'."\r\n".
  184. 'Content-Type: text/plain'."\r\n".
  185. 'Content-Transfer-Encoding: quoted-printable'."\r\n",
  186. $message->toString()
  187. );
  188. }
  189. public function testMultipleFromAddressesCanBeSet()
  190. {
  191. $message = $this->_createMessage();
  192. $message->setSubject('just a test subject');
  193. $message->setFrom(array(
  194. 'chris.corbyn@swiftmailer.org' => 'Chris Corbyn',
  195. 'mark@swiftmailer.org',
  196. ));
  197. $id = $message->getId();
  198. $date = $message->getDate();
  199. $this->assertEquals(
  200. 'Message-ID: <'.$id.'>'."\r\n".
  201. 'Date: '.date('r', $date)."\r\n".
  202. 'Subject: just a test subject'."\r\n".
  203. 'From: Chris Corbyn <chris.corbyn@swiftmailer.org>, mark@swiftmailer.org'."\r\n".
  204. 'MIME-Version: 1.0'."\r\n".
  205. 'Content-Type: text/plain'."\r\n".
  206. 'Content-Transfer-Encoding: quoted-printable'."\r\n",
  207. $message->toString()
  208. );
  209. }
  210. public function testReturnPathAddressCanBeSet()
  211. {
  212. $message = $this->_createMessage();
  213. $message->setReturnPath('chris@w3style.co.uk');
  214. $message->setSubject('just a test subject');
  215. $message->setFrom(array(
  216. 'chris.corbyn@swiftmailer.org' => 'Chris Corbyn',));
  217. $id = $message->getId();
  218. $date = $message->getDate();
  219. $this->assertEquals(
  220. 'Return-Path: <chris@w3style.co.uk>'."\r\n".
  221. 'Message-ID: <'.$id.'>'."\r\n".
  222. 'Date: '.date('r', $date)."\r\n".
  223. 'Subject: just a test subject'."\r\n".
  224. 'From: Chris Corbyn <chris.corbyn@swiftmailer.org>'."\r\n".
  225. 'MIME-Version: 1.0'."\r\n".
  226. 'Content-Type: text/plain'."\r\n".
  227. 'Content-Transfer-Encoding: quoted-printable'."\r\n",
  228. $message->toString()
  229. );
  230. }
  231. public function testEmptyReturnPathHeaderCanBeUsed()
  232. {
  233. $message = $this->_createMessage();
  234. $message->setReturnPath('');
  235. $message->setSubject('just a test subject');
  236. $message->setFrom(array(
  237. 'chris.corbyn@swiftmailer.org' => 'Chris Corbyn',));
  238. $id = $message->getId();
  239. $date = $message->getDate();
  240. $this->assertEquals(
  241. 'Return-Path: <>'."\r\n".
  242. 'Message-ID: <'.$id.'>'."\r\n".
  243. 'Date: '.date('r', $date)."\r\n".
  244. 'Subject: just a test subject'."\r\n".
  245. 'From: Chris Corbyn <chris.corbyn@swiftmailer.org>'."\r\n".
  246. 'MIME-Version: 1.0'."\r\n".
  247. 'Content-Type: text/plain'."\r\n".
  248. 'Content-Transfer-Encoding: quoted-printable'."\r\n",
  249. $message->toString()
  250. );
  251. }
  252. public function testSenderCanBeSet()
  253. {
  254. $message = $this->_createMessage();
  255. $message->setSubject('just a test subject');
  256. $message->setSender('chris.corbyn@swiftmailer.org');
  257. $id = $message->getId();
  258. $date = $message->getDate();
  259. $this->assertEquals(
  260. 'Sender: chris.corbyn@swiftmailer.org'."\r\n".
  261. 'Message-ID: <'.$id.'>'."\r\n".
  262. 'Date: '.date('r', $date)."\r\n".
  263. 'Subject: just a test subject'."\r\n".
  264. 'From: '."\r\n".
  265. 'MIME-Version: 1.0'."\r\n".
  266. 'Content-Type: text/plain'."\r\n".
  267. 'Content-Transfer-Encoding: quoted-printable'."\r\n",
  268. $message->toString()
  269. );
  270. }
  271. public function testSenderCanBeSetWithName()
  272. {
  273. $message = $this->_createMessage();
  274. $message->setSubject('just a test subject');
  275. $message->setSender(array('chris.corbyn@swiftmailer.org' => 'Chris'));
  276. $id = $message->getId();
  277. $date = $message->getDate();
  278. $this->assertEquals(
  279. 'Sender: Chris <chris.corbyn@swiftmailer.org>'."\r\n".
  280. 'Message-ID: <'.$id.'>'."\r\n".
  281. 'Date: '.date('r', $date)."\r\n".
  282. 'Subject: just a test subject'."\r\n".
  283. 'From: '."\r\n".
  284. 'MIME-Version: 1.0'."\r\n".
  285. 'Content-Type: text/plain'."\r\n".
  286. 'Content-Transfer-Encoding: quoted-printable'."\r\n",
  287. $message->toString()
  288. );
  289. }
  290. public function testReplyToCanBeSet()
  291. {
  292. $message = $this->_createMessage();
  293. $message->setSubject('just a test subject');
  294. $message->setFrom(array('chris.corbyn@swiftmailer.org' => 'Chris'));
  295. $message->setReplyTo(array('chris@w3style.co.uk' => 'Myself'));
  296. $id = $message->getId();
  297. $date = $message->getDate();
  298. $this->assertEquals(
  299. 'Message-ID: <'.$id.'>'."\r\n".
  300. 'Date: '.date('r', $date)."\r\n".
  301. 'Subject: just a test subject'."\r\n".
  302. 'From: Chris <chris.corbyn@swiftmailer.org>'."\r\n".
  303. 'Reply-To: Myself <chris@w3style.co.uk>'."\r\n".
  304. 'MIME-Version: 1.0'."\r\n".
  305. 'Content-Type: text/plain'."\r\n".
  306. 'Content-Transfer-Encoding: quoted-printable'."\r\n",
  307. $message->toString()
  308. );
  309. }
  310. public function testMultipleReplyAddressCanBeUsed()
  311. {
  312. $message = $this->_createMessage();
  313. $message->setSubject('just a test subject');
  314. $message->setFrom(array('chris.corbyn@swiftmailer.org' => 'Chris'));
  315. $message->setReplyTo(array(
  316. 'chris@w3style.co.uk' => 'Myself',
  317. 'my.other@address.com' => 'Me',
  318. ));
  319. $id = $message->getId();
  320. $date = $message->getDate();
  321. $this->assertEquals(
  322. 'Message-ID: <'.$id.'>'."\r\n".
  323. 'Date: '.date('r', $date)."\r\n".
  324. 'Subject: just a test subject'."\r\n".
  325. 'From: Chris <chris.corbyn@swiftmailer.org>'."\r\n".
  326. 'Reply-To: Myself <chris@w3style.co.uk>, Me <my.other@address.com>'."\r\n".
  327. 'MIME-Version: 1.0'."\r\n".
  328. 'Content-Type: text/plain'."\r\n".
  329. 'Content-Transfer-Encoding: quoted-printable'."\r\n",
  330. $message->toString()
  331. );
  332. }
  333. public function testToAddressCanBeSet()
  334. {
  335. $message = $this->_createMessage();
  336. $message->setSubject('just a test subject');
  337. $message->setFrom(array('chris.corbyn@swiftmailer.org' => 'Chris'));
  338. $message->setReplyTo(array(
  339. 'chris@w3style.co.uk' => 'Myself',
  340. 'my.other@address.com' => 'Me',
  341. ));
  342. $message->setTo('mark@swiftmailer.org');
  343. $id = $message->getId();
  344. $date = $message->getDate();
  345. $this->assertEquals(
  346. 'Message-ID: <'.$id.'>'."\r\n".
  347. 'Date: '.date('r', $date)."\r\n".
  348. 'Subject: just a test subject'."\r\n".
  349. 'From: Chris <chris.corbyn@swiftmailer.org>'."\r\n".
  350. 'Reply-To: Myself <chris@w3style.co.uk>, Me <my.other@address.com>'."\r\n".
  351. 'To: mark@swiftmailer.org'."\r\n".
  352. 'MIME-Version: 1.0'."\r\n".
  353. 'Content-Type: text/plain'."\r\n".
  354. 'Content-Transfer-Encoding: quoted-printable'."\r\n",
  355. $message->toString()
  356. );
  357. }
  358. public function testMultipleToAddressesCanBeSet()
  359. {
  360. $message = $this->_createMessage();
  361. $message->setSubject('just a test subject');
  362. $message->setFrom(array('chris.corbyn@swiftmailer.org' => 'Chris'));
  363. $message->setReplyTo(array(
  364. 'chris@w3style.co.uk' => 'Myself',
  365. 'my.other@address.com' => 'Me',
  366. ));
  367. $message->setTo(array(
  368. 'mark@swiftmailer.org', 'chris@swiftmailer.org' => 'Chris Corbyn',
  369. ));
  370. $id = $message->getId();
  371. $date = $message->getDate();
  372. $this->assertEquals(
  373. 'Message-ID: <'.$id.'>'."\r\n".
  374. 'Date: '.date('r', $date)."\r\n".
  375. 'Subject: just a test subject'."\r\n".
  376. 'From: Chris <chris.corbyn@swiftmailer.org>'."\r\n".
  377. 'Reply-To: Myself <chris@w3style.co.uk>, Me <my.other@address.com>'."\r\n".
  378. 'To: mark@swiftmailer.org, Chris Corbyn <chris@swiftmailer.org>'."\r\n".
  379. 'MIME-Version: 1.0'."\r\n".
  380. 'Content-Type: text/plain'."\r\n".
  381. 'Content-Transfer-Encoding: quoted-printable'."\r\n",
  382. $message->toString()
  383. );
  384. }
  385. public function testCcAddressCanBeSet()
  386. {
  387. $message = $this->_createMessage();
  388. $message->setSubject('just a test subject');
  389. $message->setFrom(array('chris.corbyn@swiftmailer.org' => 'Chris'));
  390. $message->setReplyTo(array(
  391. 'chris@w3style.co.uk' => 'Myself',
  392. 'my.other@address.com' => 'Me',
  393. ));
  394. $message->setTo(array(
  395. 'mark@swiftmailer.org', 'chris@swiftmailer.org' => 'Chris Corbyn',
  396. ));
  397. $message->setCc('john@some-site.com');
  398. $id = $message->getId();
  399. $date = $message->getDate();
  400. $this->assertEquals(
  401. 'Message-ID: <'.$id.'>'."\r\n".
  402. 'Date: '.date('r', $date)."\r\n".
  403. 'Subject: just a test subject'."\r\n".
  404. 'From: Chris <chris.corbyn@swiftmailer.org>'."\r\n".
  405. 'Reply-To: Myself <chris@w3style.co.uk>, Me <my.other@address.com>'."\r\n".
  406. 'To: mark@swiftmailer.org, Chris Corbyn <chris@swiftmailer.org>'."\r\n".
  407. 'Cc: john@some-site.com'."\r\n".
  408. 'MIME-Version: 1.0'."\r\n".
  409. 'Content-Type: text/plain'."\r\n".
  410. 'Content-Transfer-Encoding: quoted-printable'."\r\n",
  411. $message->toString()
  412. );
  413. }
  414. public function testMultipleCcAddressesCanBeSet()
  415. {
  416. $message = $this->_createMessage();
  417. $message->setSubject('just a test subject');
  418. $message->setFrom(array('chris.corbyn@swiftmailer.org' => 'Chris'));
  419. $message->setReplyTo(array(
  420. 'chris@w3style.co.uk' => 'Myself',
  421. 'my.other@address.com' => 'Me',
  422. ));
  423. $message->setTo(array(
  424. 'mark@swiftmailer.org', 'chris@swiftmailer.org' => 'Chris Corbyn',
  425. ));
  426. $message->setCc(array(
  427. 'john@some-site.com' => 'John West',
  428. 'fred@another-site.co.uk' => 'Big Fred',
  429. ));
  430. $id = $message->getId();
  431. $date = $message->getDate();
  432. $this->assertEquals(
  433. 'Message-ID: <'.$id.'>'."\r\n".
  434. 'Date: '.date('r', $date)."\r\n".
  435. 'Subject: just a test subject'."\r\n".
  436. 'From: Chris <chris.corbyn@swiftmailer.org>'."\r\n".
  437. 'Reply-To: Myself <chris@w3style.co.uk>, Me <my.other@address.com>'."\r\n".
  438. 'To: mark@swiftmailer.org, Chris Corbyn <chris@swiftmailer.org>'."\r\n".
  439. 'Cc: John West <john@some-site.com>, Big Fred <fred@another-site.co.uk>'."\r\n".
  440. 'MIME-Version: 1.0'."\r\n".
  441. 'Content-Type: text/plain'."\r\n".
  442. 'Content-Transfer-Encoding: quoted-printable'."\r\n",
  443. $message->toString()
  444. );
  445. }
  446. public function testBccAddressCanBeSet()
  447. {
  448. //Obviously Transports need to setBcc(array()) and send to each Bcc recipient
  449. // separately in accordance with RFC 2822/2821
  450. $message = $this->_createMessage();
  451. $message->setSubject('just a test subject');
  452. $message->setFrom(array('chris.corbyn@swiftmailer.org' => 'Chris'));
  453. $message->setReplyTo(array(
  454. 'chris@w3style.co.uk' => 'Myself',
  455. 'my.other@address.com' => 'Me',
  456. ));
  457. $message->setTo(array(
  458. 'mark@swiftmailer.org', 'chris@swiftmailer.org' => 'Chris Corbyn',
  459. ));
  460. $message->setCc(array(
  461. 'john@some-site.com' => 'John West',
  462. 'fred@another-site.co.uk' => 'Big Fred',
  463. ));
  464. $message->setBcc('x@alphabet.tld');
  465. $id = $message->getId();
  466. $date = $message->getDate();
  467. $this->assertEquals(
  468. 'Message-ID: <'.$id.'>'."\r\n".
  469. 'Date: '.date('r', $date)."\r\n".
  470. 'Subject: just a test subject'."\r\n".
  471. 'From: Chris <chris.corbyn@swiftmailer.org>'."\r\n".
  472. 'Reply-To: Myself <chris@w3style.co.uk>, Me <my.other@address.com>'."\r\n".
  473. 'To: mark@swiftmailer.org, Chris Corbyn <chris@swiftmailer.org>'."\r\n".
  474. 'Cc: John West <john@some-site.com>, Big Fred <fred@another-site.co.uk>'."\r\n".
  475. 'Bcc: x@alphabet.tld'."\r\n".
  476. 'MIME-Version: 1.0'."\r\n".
  477. 'Content-Type: text/plain'."\r\n".
  478. 'Content-Transfer-Encoding: quoted-printable'."\r\n",
  479. $message->toString()
  480. );
  481. }
  482. public function testMultipleBccAddressesCanBeSet()
  483. {
  484. //Obviously Transports need to setBcc(array()) and send to each Bcc recipient
  485. // separately in accordance with RFC 2822/2821
  486. $message = $this->_createMessage();
  487. $message->setSubject('just a test subject');
  488. $message->setFrom(array('chris.corbyn@swiftmailer.org' => 'Chris'));
  489. $message->setReplyTo(array(
  490. 'chris@w3style.co.uk' => 'Myself',
  491. 'my.other@address.com' => 'Me',
  492. ));
  493. $message->setTo(array(
  494. 'mark@swiftmailer.org', 'chris@swiftmailer.org' => 'Chris Corbyn',
  495. ));
  496. $message->setCc(array(
  497. 'john@some-site.com' => 'John West',
  498. 'fred@another-site.co.uk' => 'Big Fred',
  499. ));
  500. $message->setBcc(array('x@alphabet.tld', 'a@alphabet.tld' => 'A'));
  501. $id = $message->getId();
  502. $date = $message->getDate();
  503. $this->assertEquals(
  504. 'Message-ID: <'.$id.'>'."\r\n".
  505. 'Date: '.date('r', $date)."\r\n".
  506. 'Subject: just a test subject'."\r\n".
  507. 'From: Chris <chris.corbyn@swiftmailer.org>'."\r\n".
  508. 'Reply-To: Myself <chris@w3style.co.uk>, Me <my.other@address.com>'."\r\n".
  509. 'To: mark@swiftmailer.org, Chris Corbyn <chris@swiftmailer.org>'."\r\n".
  510. 'Cc: John West <john@some-site.com>, Big Fred <fred@another-site.co.uk>'."\r\n".
  511. 'Bcc: x@alphabet.tld, A <a@alphabet.tld>'."\r\n".
  512. 'MIME-Version: 1.0'."\r\n".
  513. 'Content-Type: text/plain'."\r\n".
  514. 'Content-Transfer-Encoding: quoted-printable'."\r\n",
  515. $message->toString()
  516. );
  517. }
  518. public function testStringBodyIsAppended()
  519. {
  520. $message = $this->_createMessage();
  521. $message->setReturnPath('chris@w3style.co.uk');
  522. $message->setSubject('just a test subject');
  523. $message->setFrom(array(
  524. 'chris.corbyn@swiftmailer.org' => 'Chris Corbyn',));
  525. $message->setBody(
  526. 'just a test body'."\r\n".
  527. 'with a new line'
  528. );
  529. $id = $message->getId();
  530. $date = $message->getDate();
  531. $this->assertEquals(
  532. 'Return-Path: <chris@w3style.co.uk>'."\r\n".
  533. 'Message-ID: <'.$id.'>'."\r\n".
  534. 'Date: '.date('r', $date)."\r\n".
  535. 'Subject: just a test subject'."\r\n".
  536. 'From: Chris Corbyn <chris.corbyn@swiftmailer.org>'."\r\n".
  537. 'MIME-Version: 1.0'."\r\n".
  538. 'Content-Type: text/plain'."\r\n".
  539. 'Content-Transfer-Encoding: quoted-printable'."\r\n".
  540. "\r\n".
  541. 'just a test body'."\r\n".
  542. 'with a new line',
  543. $message->toString()
  544. );
  545. }
  546. public function testStringBodyIsEncoded()
  547. {
  548. $message = $this->_createMessage();
  549. $message->setReturnPath('chris@w3style.co.uk');
  550. $message->setSubject('just a test subject');
  551. $message->setFrom(array(
  552. 'chris.corbyn@swiftmailer.org' => 'Chris Corbyn',));
  553. $message->setBody(
  554. 'Just s'.pack('C*', 0xC2, 0x01, 0x01).'me multi-'."\r\n".
  555. 'line message!'
  556. );
  557. $id = $message->getId();
  558. $date = $message->getDate();
  559. $this->assertEquals(
  560. 'Return-Path: <chris@w3style.co.uk>'."\r\n".
  561. 'Message-ID: <'.$id.'>'."\r\n".
  562. 'Date: '.date('r', $date)."\r\n".
  563. 'Subject: just a test subject'."\r\n".
  564. 'From: Chris Corbyn <chris.corbyn@swiftmailer.org>'."\r\n".
  565. 'MIME-Version: 1.0'."\r\n".
  566. 'Content-Type: text/plain'."\r\n".
  567. 'Content-Transfer-Encoding: quoted-printable'."\r\n".
  568. "\r\n".
  569. 'Just s=C2=01=01me multi-'."\r\n".
  570. 'line message!',
  571. $message->toString()
  572. );
  573. }
  574. public function testChildrenCanBeAttached()
  575. {
  576. $message = $this->_createMessage();
  577. $message->setReturnPath('chris@w3style.co.uk');
  578. $message->setSubject('just a test subject');
  579. $message->setFrom(array(
  580. 'chris.corbyn@swiftmailer.org' => 'Chris Corbyn',));
  581. $id = $message->getId();
  582. $date = $message->getDate();
  583. $boundary = $message->getBoundary();
  584. $part1 = $this->_createMimePart();
  585. $part1->setContentType('text/plain');
  586. $part1->setCharset('iso-8859-1');
  587. $part1->setBody('foo');
  588. $message->attach($part1);
  589. $part2 = $this->_createMimePart();
  590. $part2->setContentType('text/html');
  591. $part2->setCharset('iso-8859-1');
  592. $part2->setBody('test <b>foo</b>');
  593. $message->attach($part2);
  594. $this->assertEquals(
  595. 'Return-Path: <chris@w3style.co.uk>'."\r\n".
  596. 'Message-ID: <'.$id.'>'."\r\n".
  597. 'Date: '.date('r', $date)."\r\n".
  598. 'Subject: just a test subject'."\r\n".
  599. 'From: Chris Corbyn <chris.corbyn@swiftmailer.org>'."\r\n".
  600. 'MIME-Version: 1.0'."\r\n".
  601. 'Content-Type: multipart/alternative;'."\r\n".
  602. ' boundary="'.$boundary.'"'."\r\n".
  603. "\r\n\r\n".
  604. '--'.$boundary."\r\n".
  605. 'Content-Type: text/plain; charset=iso-8859-1'."\r\n".
  606. 'Content-Transfer-Encoding: quoted-printable'."\r\n".
  607. "\r\n".
  608. 'foo'.
  609. "\r\n\r\n".
  610. '--'.$boundary."\r\n".
  611. 'Content-Type: text/html; charset=iso-8859-1'."\r\n".
  612. 'Content-Transfer-Encoding: quoted-printable'."\r\n".
  613. "\r\n".
  614. 'test <b>foo</b>'.
  615. "\r\n\r\n".
  616. '--'.$boundary.'--'."\r\n",
  617. $message->toString()
  618. );
  619. }
  620. public function testAttachmentsBeingAttached()
  621. {
  622. $message = $this->_createMessage();
  623. $message->setReturnPath('chris@w3style.co.uk');
  624. $message->setSubject('just a test subject');
  625. $message->setFrom(array(
  626. 'chris.corbyn@swiftmailer.org' => 'Chris Corbyn',));
  627. $id = $message->getId();
  628. $date = preg_quote(date('r', $message->getDate()), '~');
  629. $boundary = $message->getBoundary();
  630. $part = $this->_createMimePart();
  631. $part->setContentType('text/plain');
  632. $part->setCharset('iso-8859-1');
  633. $part->setBody('foo');
  634. $message->attach($part);
  635. $attachment = $this->_createAttachment();
  636. $attachment->setContentType('application/pdf');
  637. $attachment->setFilename('foo.pdf');
  638. $attachment->setBody('<pdf data>');
  639. $message->attach($attachment);
  640. $this->assertRegExp(
  641. '~^'.
  642. 'Return-Path: <chris@w3style.co.uk>'."\r\n".
  643. 'Message-ID: <'.$id.'>'."\r\n".
  644. 'Date: '.$date."\r\n".
  645. 'Subject: just a test subject'."\r\n".
  646. 'From: Chris Corbyn <chris.corbyn@swiftmailer.org>'."\r\n".
  647. 'MIME-Version: 1.0'."\r\n".
  648. 'Content-Type: multipart/mixed;'."\r\n".
  649. ' boundary="'.$boundary.'"'."\r\n".
  650. "\r\n\r\n".
  651. '--'.$boundary."\r\n".
  652. 'Content-Type: multipart/alternative;'."\r\n".
  653. ' boundary="(.*?)"'."\r\n".
  654. "\r\n\r\n".
  655. '--\\1'."\r\n".
  656. 'Content-Type: text/plain; charset=iso-8859-1'."\r\n".
  657. 'Content-Transfer-Encoding: quoted-printable'."\r\n".
  658. "\r\n".
  659. 'foo'.
  660. "\r\n\r\n".
  661. '--\\1--'."\r\n".
  662. "\r\n\r\n".
  663. '--'.$boundary."\r\n".
  664. 'Content-Type: application/pdf; name=foo.pdf'."\r\n".
  665. 'Content-Transfer-Encoding: base64'."\r\n".
  666. 'Content-Disposition: attachment; filename=foo.pdf'."\r\n".
  667. "\r\n".
  668. preg_quote(base64_encode('<pdf data>'), '~').
  669. "\r\n\r\n".
  670. '--'.$boundary.'--'."\r\n".
  671. '$~D',
  672. $message->toString()
  673. );
  674. }
  675. public function testAttachmentsAndEmbeddedFilesBeingAttached()
  676. {
  677. $message = $this->_createMessage();
  678. $message->setReturnPath('chris@w3style.co.uk');
  679. $message->setSubject('just a test subject');
  680. $message->setFrom(array(
  681. 'chris.corbyn@swiftmailer.org' => 'Chris Corbyn',));
  682. $id = $message->getId();
  683. $date = preg_quote(date('r', $message->getDate()), '~');
  684. $boundary = $message->getBoundary();
  685. $part = $this->_createMimePart();
  686. $part->setContentType('text/plain');
  687. $part->setCharset('iso-8859-1');
  688. $part->setBody('foo');
  689. $message->attach($part);
  690. $attachment = $this->_createAttachment();
  691. $attachment->setContentType('application/pdf');
  692. $attachment->setFilename('foo.pdf');
  693. $attachment->setBody('<pdf data>');
  694. $message->attach($attachment);
  695. $file = $this->_createEmbeddedFile();
  696. $file->setContentType('image/jpeg');
  697. $file->setFilename('myimage.jpg');
  698. $file->setBody('<image data>');
  699. $message->attach($file);
  700. $cid = $file->getId();
  701. $this->assertRegExp(
  702. '~^'.
  703. 'Return-Path: <chris@w3style.co.uk>'."\r\n".
  704. 'Message-ID: <'.$id.'>'."\r\n".
  705. 'Date: '.$date."\r\n".
  706. 'Subject: just a test subject'."\r\n".
  707. 'From: Chris Corbyn <chris.corbyn@swiftmailer.org>'."\r\n".
  708. 'MIME-Version: 1.0'."\r\n".
  709. 'Content-Type: multipart/mixed;'."\r\n".
  710. ' boundary="'.$boundary.'"'."\r\n".
  711. "\r\n\r\n".
  712. '--'.$boundary."\r\n".
  713. 'Content-Type: multipart/alternative;'."\r\n".
  714. ' boundary="(.*?)"'."\r\n".
  715. "\r\n\r\n".
  716. '--\\1'."\r\n".
  717. 'Content-Type: text/plain; charset=iso-8859-1'."\r\n".
  718. 'Content-Transfer-Encoding: quoted-printable'."\r\n".
  719. "\r\n".
  720. 'foo'.
  721. "\r\n\r\n".
  722. '--\\1'."\r\n".
  723. 'Content-Type: multipart/related;'."\r\n".
  724. ' boundary="(.*?)"'."\r\n".
  725. "\r\n\r\n".
  726. '--\\2'."\r\n".
  727. 'Content-Type: image/jpeg; name=myimage.jpg'."\r\n".
  728. 'Content-Transfer-Encoding: base64'."\r\n".
  729. 'Content-Disposition: inline; filename=myimage.jpg'."\r\n".
  730. 'Content-ID: <'.$cid.'>'."\r\n".
  731. "\r\n".
  732. preg_quote(base64_encode('<image data>'), '~').
  733. "\r\n\r\n".
  734. '--\\2--'."\r\n".
  735. "\r\n\r\n".
  736. '--\\1--'."\r\n".
  737. "\r\n\r\n".
  738. '--'.$boundary."\r\n".
  739. 'Content-Type: application/pdf; name=foo.pdf'."\r\n".
  740. 'Content-Transfer-Encoding: base64'."\r\n".
  741. 'Content-Disposition: attachment; filename=foo.pdf'."\r\n".
  742. "\r\n".
  743. preg_quote(base64_encode('<pdf data>'), '~').
  744. "\r\n\r\n".
  745. '--'.$boundary.'--'."\r\n".
  746. '$~D',
  747. $message->toString()
  748. );
  749. }
  750. public function testComplexEmbeddingOfContent()
  751. {
  752. $message = $this->_createMessage();
  753. $message->setReturnPath('chris@w3style.co.uk');
  754. $message->setSubject('just a test subject');
  755. $message->setFrom(array(
  756. 'chris.corbyn@swiftmailer.org' => 'Chris Corbyn',));
  757. $id = $message->getId();
  758. $date = preg_quote(date('r', $message->getDate()), '~');
  759. $boundary = $message->getBoundary();
  760. $attachment = $this->_createAttachment();
  761. $attachment->setContentType('application/pdf');
  762. $attachment->setFilename('foo.pdf');
  763. $attachment->setBody('<pdf data>');
  764. $message->attach($attachment);
  765. $file = $this->_createEmbeddedFile();
  766. $file->setContentType('image/jpeg');
  767. $file->setFilename('myimage.jpg');
  768. $file->setBody('<image data>');
  769. $part = $this->_createMimePart();
  770. $part->setContentType('text/html');
  771. $part->setCharset('iso-8859-1');
  772. $part->setBody('foo <img src="'.$message->embed($file).'" />');
  773. $message->attach($part);
  774. $cid = $file->getId();
  775. $this->assertRegExp(
  776. '~^'.
  777. 'Return-Path: <chris@w3style.co.uk>'."\r\n".
  778. 'Message-ID: <'.$id.'>'."\r\n".
  779. 'Date: '.$date."\r\n".
  780. 'Subject: just a test subject'."\r\n".
  781. 'From: Chris Corbyn <chris.corbyn@swiftmailer.org>'."\r\n".
  782. 'MIME-Version: 1.0'."\r\n".
  783. 'Content-Type: multipart/mixed;'."\r\n".
  784. ' boundary="'.$boundary.'"'."\r\n".
  785. "\r\n\r\n".
  786. '--'.$boundary."\r\n".
  787. 'Content-Type: multipart/related;'."\r\n".
  788. ' boundary="(.*?)"'."\r\n".
  789. "\r\n\r\n".
  790. '--\\1'."\r\n".
  791. 'Content-Type: text/html; charset=iso-8859-1'."\r\n".
  792. 'Content-Transfer-Encoding: quoted-printable'."\r\n".
  793. "\r\n".
  794. 'foo <img src=3D"cid:'.$cid.'" />'.//=3D is just = in QP
  795. "\r\n\r\n".
  796. '--\\1'."\r\n".
  797. 'Content-Type: image/jpeg; name=myimage.jpg'."\r\n".
  798. 'Content-Transfer-Encoding: base64'."\r\n".
  799. 'Content-Disposition: inline; filename=myimage.jpg'."\r\n".
  800. 'Content-ID: <'.$cid.'>'."\r\n".
  801. "\r\n".
  802. preg_quote(base64_encode('<image data>'), '~').
  803. "\r\n\r\n".
  804. '--\\1--'."\r\n".
  805. "\r\n\r\n".
  806. '--'.$boundary."\r\n".
  807. 'Content-Type: application/pdf; name=foo.pdf'."\r\n".
  808. 'Content-Transfer-Encoding: base64'."\r\n".
  809. 'Content-Disposition: attachment; filename=foo.pdf'."\r\n".
  810. "\r\n".
  811. preg_quote(base64_encode('<pdf data>'), '~').
  812. "\r\n\r\n".
  813. '--'.$boundary.'--'."\r\n".
  814. '$~D',
  815. $message->toString()
  816. );
  817. }
  818. public function testAttachingAndDetachingContent()
  819. {
  820. $message = $this->_createMessage();
  821. $message->setReturnPath('chris@w3style.co.uk');
  822. $message->setSubject('just a test subject');
  823. $message->setFrom(array(
  824. 'chris.corbyn@swiftmailer.org' => 'Chris Corbyn',));
  825. $id = $message->getId();
  826. $date = preg_quote(date('r', $message->getDate()), '~');
  827. $boundary = $message->getBoundary();
  828. $part = $this->_createMimePart();
  829. $part->setContentType('text/plain');
  830. $part->setCharset('iso-8859-1');
  831. $part->setBody('foo');
  832. $message->attach($part);
  833. $attachment = $this->_createAttachment();
  834. $attachment->setContentType('application/pdf');
  835. $attachment->setFilename('foo.pdf');
  836. $attachment->setBody('<pdf data>');
  837. $message->attach($attachment);
  838. $file = $this->_createEmbeddedFile();
  839. $file->setContentType('image/jpeg');
  840. $file->setFilename('myimage.jpg');
  841. $file->setBody('<image data>');
  842. $message->attach($file);
  843. $cid = $file->getId();
  844. $message->detach($attachment);
  845. $this->assertRegExp(
  846. '~^'.
  847. 'Return-Path: <chris@w3style.co.uk>'."\r\n".
  848. 'Message-ID: <'.$id.'>'."\r\n".
  849. 'Date: '.$date."\r\n".
  850. 'Subject: just a test subject'."\r\n".
  851. 'From: Chris Corbyn <chris.corbyn@swiftmailer.org>'."\r\n".
  852. 'MIME-Version: 1.0'."\r\n".
  853. 'Content-Type: multipart/alternative;'."\r\n".
  854. ' boundary="'.$boundary.'"'."\r\n".
  855. "\r\n\r\n".
  856. '--'.$boundary."\r\n".
  857. 'Content-Type: text/plain; charset=iso-8859-1'."\r\n".
  858. 'Content-Transfer-Encoding: quoted-printable'."\r\n".
  859. "\r\n".
  860. 'foo'.
  861. "\r\n\r\n".
  862. '--'.$boundary."\r\n".
  863. 'Content-Type: multipart/related;'."\r\n".
  864. ' boundary="(.*?)"'."\r\n".
  865. "\r\n\r\n".
  866. '--\\1'."\r\n".
  867. 'Content-Type: image/jpeg; name=myimage.jpg'."\r\n".
  868. 'Content-Transfer-Encoding: base64'."\r\n".
  869. 'Content-Disposition: inline; filename=myimage.jpg'."\r\n".
  870. 'Content-ID: <'.$cid.'>'."\r\n".
  871. "\r\n".
  872. preg_quote(base64_encode('<image data>'), '~').
  873. "\r\n\r\n".
  874. '--\\1--'."\r\n".
  875. "\r\n\r\n".
  876. '--'.$boundary.'--'."\r\n".
  877. '$~D',
  878. $message->toString(),
  879. '%s: Attachment should have been detached'
  880. );
  881. }
  882. public function testBoundaryDoesNotAppearAfterAllPartsAreDetached()
  883. {
  884. $message = $this->_createMessage();
  885. $message->setReturnPath('chris@w3style.co.uk');
  886. $message->setSubject('just a test subject');
  887. $message->setFrom(array(
  888. 'chris.corbyn@swiftmailer.org' => 'Chris Corbyn',));
  889. $id = $message->getId();
  890. $date = $message->getDate();
  891. $boundary = $message->getBoundary();
  892. $part1 = $this->_createMimePart();
  893. $part1->setContentType('text/plain');
  894. $part1->setCharset('iso-8859-1');
  895. $part1->setBody('foo');
  896. $message->attach($part1);
  897. $part2 = $this->_createMimePart();
  898. $part2->setContentType('text/html');
  899. $part2->setCharset('iso-8859-1');
  900. $part2->setBody('test <b>foo</b>');
  901. $message->attach($part2);
  902. $message->detach($part1);
  903. $message->detach($part2);
  904. $this->assertEquals(
  905. 'Return-Path: <chris@w3style.co.uk>'."\r\n".
  906. 'Message-ID: <'.$id.'>'."\r\n".
  907. 'Date: '.date('r', $date)."\r\n".
  908. 'Subject: just a test subject'."\r\n".
  909. 'From: Chris Corbyn <chris.corbyn@swiftmailer.org>'."\r\n".
  910. 'MIME-Version: 1.0'."\r\n".
  911. 'Content-Type: text/plain'."\r\n".
  912. 'Content-Transfer-Encoding: quoted-printable'."\r\n",
  913. $message->toString(),
  914. '%s: Message should be restored to orignal state after parts are detached'
  915. );
  916. }
  917. public function testCharsetFormatOrDelSpAreNotShownWhenBoundaryIsSet()
  918. {
  919. $message = $this->_createMessage();
  920. $message->setReturnPath('chris@w3style.co.uk');
  921. $message->setSubject('just a test subject');
  922. $message->setFrom(array(
  923. 'chris.corbyn@swiftmailer.org' => 'Chris Corbyn',));
  924. $message->setCharset('utf-8');
  925. $message->setFormat('flowed');
  926. $message->setDelSp(true);
  927. $id = $message->getId();
  928. $date = $message->getDate();
  929. $boundary = $message->getBoundary();
  930. $part1 = $this->_createMimePart();
  931. $part1->setContentType('text/plain');
  932. $part1->setCharset('iso-8859-1');
  933. $part1->setBody('foo');
  934. $message->attach($part1);
  935. $part2 = $this->_createMimePart();
  936. $part2->setContentType('text/html');
  937. $part2->setCharset('iso-8859-1');
  938. $part2->setBody('test <b>foo</b>');
  939. $message->attach($part2);
  940. $this->assertEquals(
  941. 'Return-Path: <chris@w3style.co.uk>'."\r\n".
  942. 'Message-ID: <'.$id.'>'."\r\n".
  943. 'Date: '.date('r', $date)."\r\n".
  944. 'Subject: just a test subject'."\r\n".
  945. 'From: Chris Corbyn <chris.corbyn@swiftmailer.org>'."\r\n".
  946. 'MIME-Version: 1.0'."\r\n".
  947. 'Content-Type: multipart/alternative;'."\r\n".
  948. ' boundary="'.$boundary.'"'."\r\n".
  949. "\r\n\r\n".
  950. '--'.$boundary."\r\n".
  951. 'Content-Type: text/plain; charset=iso-8859-1'."\r\n".
  952. 'Content-Transfer-Encoding: quoted-printable'."\r\n".
  953. "\r\n".
  954. 'foo'.
  955. "\r\n\r\n".
  956. '--'.$boundary."\r\n".
  957. 'Content-Type: text/html; charset=iso-8859-1'."\r\n".
  958. 'Content-Transfer-Encoding: quoted-printable'."\r\n".
  959. "\r\n".
  960. 'test <b>foo</b>'.
  961. "\r\n\r\n".
  962. '--'.$boundary.'--'."\r\n",
  963. $message->toString()
  964. );
  965. }
  966. public function testBodyCanBeSetWithAttachments()
  967. {
  968. $message = $this->_createMessage();
  969. $message->setReturnPath('chris@w3style.co.uk');
  970. $message->setSubject('just a test subject');
  971. $message->setFrom(array(
  972. 'chris.corbyn@swiftmailer.org' => 'Chris Corbyn',));
  973. $message->setContentType('text/html');
  974. $message->setCharset('iso-8859-1');
  975. $message->setBody('foo');
  976. $id = $message->getId();
  977. $date = date('r', $message->getDate());
  978. $boundary = $message->getBoundary();
  979. $attachment = $this->_createAttachment();
  980. $attachment->setContentType('application/pdf');
  981. $attachment->setFilename('foo.pdf');
  982. $attachment->setBody('<pdf data>');
  983. $message->attach($attachment);
  984. $this->assertEquals(
  985. 'Return-Path: <chris@w3style.co.uk>'."\r\n".
  986. 'Message-ID: <'.$id.'>'."\r\n".
  987. 'Date: '.$date."\r\n".
  988. 'Subject: just a test subject'."\r\n".
  989. 'From: Chris Corbyn <chris.corbyn@swiftmailer.org>'."\r\n".
  990. 'MIME-Version: 1.0'."\r\n".
  991. 'Content-Type: multipart/mixed;'."\r\n".
  992. ' boundary="'.$boundary.'"'."\r\n".
  993. "\r\n\r\n".
  994. '--'.$boundary."\r\n".
  995. 'Content-Type: text/html; charset=iso-8859-1'."\r\n".
  996. 'Content-Transfer-Encoding: quoted-printable'."\r\n".
  997. "\r\n".
  998. 'foo'.
  999. "\r\n\r\n".
  1000. '--'.$boundary."\r\n".
  1001. 'Content-Type: application/pdf; name=foo.pdf'."\r\n".
  1002. 'Content-Transfer-Encoding: base64'."\r\n".
  1003. 'Content-Disposition: attachment; filename=foo.pdf'."\r\n".
  1004. "\r\n".
  1005. base64_encode('<pdf data>').
  1006. "\r\n\r\n".
  1007. '--'.$boundary.'--'."\r\n",
  1008. $message->toString()
  1009. );
  1010. }
  1011. public function testHtmlPartAlwaysAppearsLast()
  1012. {
  1013. $message = $this->_createMessage();
  1014. $message->setReturnPath('chris@w3style.co.uk');
  1015. $message->setSubject('just a test subject');
  1016. $message->setFrom(array(
  1017. 'chris.corbyn@swiftmailer.org' => 'Chris Corbyn',));
  1018. $id = $message->getId();
  1019. $date = date('r', $message->getDate());
  1020. $boundary = $message->getBoundary();
  1021. $part1 = $this->_createMimePart();
  1022. $part1->setContentType('text/html');
  1023. $part1->setBody('foo');
  1024. $part2 = $this->_createMimePart();
  1025. $part2->setContentType('text/plain');
  1026. $part2->setBody('bar');
  1027. $message->attach($part1);
  1028. $message->attach($part2);
  1029. $this->assertEquals(
  1030. 'Return-Path: <chris@w3style.co.uk>'."\r\n".
  1031. 'Message-ID: <'.$id.'>'."\r\n".
  1032. 'Date: '.$date."\r\n".
  1033. 'Subject: just a test subject'."\r\n".
  1034. 'From: Chris Corbyn <chris.corbyn@swiftmailer.org>'."\r\n".
  1035. 'MIME-Version: 1.0'."\r\n".
  1036. 'Content-Type: multipart/alternative;'."\r\n".
  1037. ' boundary="'.$boundary.'"'."\r\n".
  1038. "\r\n\r\n".
  1039. '--'.$boundary."\r\n".
  1040. 'Content-Type: text/plain'."\r\n".
  1041. 'Content-Transfer-Encoding: quoted-printable'."\r\n".
  1042. "\r\n".
  1043. 'bar'.
  1044. "\r\n\r\n".
  1045. '--'.$boundary."\r\n".
  1046. 'Content-Type: text/html'."\r\n".
  1047. 'Content-Transfer-Encoding: quoted-printable'."\r\n".
  1048. "\r\n".
  1049. 'foo'.
  1050. "\r\n\r\n".
  1051. '--'.$boundary.'--'."\r\n",
  1052. $message->toString()
  1053. );
  1054. }
  1055. public function testBodyBecomesPartIfOtherPartsAttached()
  1056. {
  1057. $message = $this->_createMessage();
  1058. $message->setReturnPath('chris@w3style.co.uk');
  1059. $message->setSubject('just a test subject');
  1060. $message->setFrom(array(
  1061. 'chris.corbyn@swiftmailer.org' => 'Chris Corbyn',));
  1062. $message->setContentType('text/html');
  1063. $message->setBody('foo');
  1064. $id = $message->getId();
  1065. $date = date('r', $message->getDate());
  1066. $boundary = $message->getBoundary();
  1067. $part2 = $this->_createMimePart();
  1068. $part2->setContentType('text/plain');
  1069. $part2->setBody('bar');
  1070. $message->attach($part2);
  1071. $this->assertEquals(
  1072. 'Return-Path: <chris@w3style.co.uk>'."\r\n".
  1073. 'Message-ID: <'.$id.'>'."\r\n".
  1074. 'Date: '.$date."\r\n".
  1075. 'Subject: just a test subject'."\r\n".
  1076. 'From: Chris Corbyn <chris.corbyn@swiftmailer.org>'."\r\n".
  1077. 'MIME-Version: 1.0'."\r\n".
  1078. 'Content-Type: multipart/alternative;'."\r\n".
  1079. ' boundary="'.$boundary.'"'."\r\n".
  1080. "\r\n\r\n".
  1081. '--'.$boundary."\r\n".
  1082. 'Content-Type: text/plain'."\r\n".
  1083. 'Content-Transfer-Encoding: quoted-printable'."\r\n".
  1084. "\r\n".
  1085. 'bar'.
  1086. "\r\n\r\n".
  1087. '--'.$boundary."\r\n".
  1088. 'Content-Type: text/html'."\r\n".
  1089. 'Content-Transfer-Encoding: quoted-printable'."\r\n".
  1090. "\r\n".
  1091. 'foo'.
  1092. "\r\n\r\n".
  1093. '--'.$boundary.'--'."\r\n",
  1094. $message->toString()
  1095. );
  1096. }
  1097. public function testBodyIsCanonicalized()
  1098. {
  1099. $message = $this->_createMessage();
  1100. $message->setReturnPath('chris@w3style.co.uk');
  1101. $message->setSubject('just a test subject');
  1102. $message->setFrom(array(
  1103. 'chris.corbyn@swiftmailer.org' => 'Chris Corbyn',));
  1104. $message->setBody(
  1105. 'just a test body'."\n".
  1106. 'with a new line'
  1107. );
  1108. $id = $message->getId();
  1109. $date = $message->getDate();
  1110. $this->assertEquals(
  1111. 'Return-Path: <chris@w3style.co.uk>'."\r\n".
  1112. 'Message-ID: <'.$id.'>'."\r\n".
  1113. 'Date: '.date('r', $date)."\r\n".
  1114. 'Subject: just a test subject'."\r\n".
  1115. 'From: Chris Corbyn <chris.corbyn@swiftmailer.org>'."\r\n".
  1116. 'MIME-Version: 1.0'."\r\n".
  1117. 'Content-Type: text/plain'."\r\n".
  1118. 'Content-Transfer-Encoding: quoted-printable'."\r\n".
  1119. "\r\n".
  1120. 'just a test body'."\r\n".
  1121. 'with a new line',
  1122. $message->toString()
  1123. );
  1124. }
  1125. // -- Private helpers
  1126. protected function _createMessage()
  1127. {
  1128. return new Swift_Message();
  1129. }
  1130. protected function _createMimePart()
  1131. {
  1132. return new Swift_MimePart();
  1133. }
  1134. protected function _createAttachment()
  1135. {
  1136. return new Swift_Attachment();
  1137. }
  1138. protected function _createEmbeddedFile()
  1139. {
  1140. return new Swift_EmbeddedFile();
  1141. }
  1142. }