|
| 1 | +<?php |
| 2 | + |
| 3 | +use DirectoryTree\ImapEngine\BodyStructurePart; |
| 4 | +use DirectoryTree\ImapEngine\Support\MimeMessage; |
| 5 | + |
| 6 | +test('it builds mime message with content type', function () { |
| 7 | + $part = new BodyStructurePart( |
| 8 | + partNumber: '1', |
| 9 | + type: 'text', |
| 10 | + subtype: 'plain', |
| 11 | + ); |
| 12 | + |
| 13 | + $mime = MimeMessage::make($part, 'Hello World!'); |
| 14 | + |
| 15 | + expect($mime)->toBe("Content-Type: text/plain\r\n\r\nHello World!"); |
| 16 | +}); |
| 17 | + |
| 18 | +test('it builds mime message with charset', function () { |
| 19 | + $part = new BodyStructurePart( |
| 20 | + partNumber: '1', |
| 21 | + type: 'text', |
| 22 | + subtype: 'plain', |
| 23 | + parameters: ['charset' => 'utf-8'], |
| 24 | + ); |
| 25 | + |
| 26 | + $mime = MimeMessage::make($part, 'Hello World!'); |
| 27 | + |
| 28 | + expect($mime)->toBe("Content-Type: text/plain; charset=\"utf-8\"\r\n\r\nHello World!"); |
| 29 | +}); |
| 30 | + |
| 31 | +test('it builds mime message with transfer encoding', function () { |
| 32 | + $part = new BodyStructurePart( |
| 33 | + partNumber: '1', |
| 34 | + type: 'text', |
| 35 | + subtype: 'plain', |
| 36 | + encoding: 'base64', |
| 37 | + ); |
| 38 | + |
| 39 | + $mime = MimeMessage::make($part, 'SGVsbG8gV29ybGQh'); |
| 40 | + |
| 41 | + expect($mime)->toBe("Content-Type: text/plain\r\nContent-Transfer-Encoding: base64\r\n\r\nSGVsbG8gV29ybGQh"); |
| 42 | +}); |
| 43 | + |
| 44 | +test('it builds mime message with charset and transfer encoding', function () { |
| 45 | + $part = new BodyStructurePart( |
| 46 | + partNumber: '1', |
| 47 | + type: 'text', |
| 48 | + subtype: 'plain', |
| 49 | + parameters: ['charset' => 'utf-8'], |
| 50 | + encoding: 'quoted-printable', |
| 51 | + ); |
| 52 | + |
| 53 | + $mime = MimeMessage::make($part, 'Hello=20World!'); |
| 54 | + |
| 55 | + expect($mime)->toBe("Content-Type: text/plain; charset=\"utf-8\"\r\nContent-Transfer-Encoding: quoted-printable\r\n\r\nHello=20World!"); |
| 56 | +}); |
| 57 | + |
| 58 | +test('it builds mime message for html content', function () { |
| 59 | + $part = new BodyStructurePart( |
| 60 | + partNumber: '1', |
| 61 | + type: 'text', |
| 62 | + subtype: 'html', |
| 63 | + parameters: ['charset' => 'utf-8'], |
| 64 | + encoding: '7bit', |
| 65 | + ); |
| 66 | + |
| 67 | + $mime = MimeMessage::make($part, '<p>Hello World!</p>'); |
| 68 | + |
| 69 | + expect($mime)->toBe("Content-Type: text/html; charset=\"utf-8\"\r\nContent-Transfer-Encoding: 7bit\r\n\r\n<p>Hello World!</p>"); |
| 70 | +}); |
| 71 | + |
| 72 | +test('it builds mime message with iso-8859-1 charset', function () { |
| 73 | + $part = new BodyStructurePart( |
| 74 | + partNumber: '1', |
| 75 | + type: 'text', |
| 76 | + subtype: 'plain', |
| 77 | + parameters: ['charset' => 'iso-8859-1'], |
| 78 | + encoding: 'quoted-printable', |
| 79 | + ); |
| 80 | + |
| 81 | + $mime = MimeMessage::make($part, 'Caf=E9'); |
| 82 | + |
| 83 | + expect($mime)->toBe("Content-Type: text/plain; charset=\"iso-8859-1\"\r\nContent-Transfer-Encoding: quoted-printable\r\n\r\nCaf=E9"); |
| 84 | +}); |
| 85 | + |
0 commit comments