Completed
Push — master ( 74fe50...0f19ea )
by Zaahid
09:04
created

UUEncodedPart   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 1
dl 0
loc 61
ccs 18
cts 18
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 20 1
A getUnixFileMode() 0 4 1
A getFilename() 0 4 1
1
<?php
2
/**
3
 * This file is part of the ZBateson\MailMimeParser project.
4
 *
5
 * @license http://opensource.org/licenses/bsd-license.php BSD
6
 */
7
namespace ZBateson\MailMimeParser\Message;
8
9
use ZBateson\MailMimeParser\Header\HeaderFactory;
10
use ZBateson\MailMimeParser\Message\Writer\MimePartWriter;
11
12
/**
13
 * A specialized NonMimePart representing a uuencoded part.
14
 * 
15
 * This represents part of a message that is not a mime message.  A multi-part
16
 * mime message may have a part with a Content-Transfer-Encoding of x-uuencode
17
 * but that would be represented by a normal MimePart.
18
 * 
19
 * UUEncodedPart extends NonMimePart to return a Content-Transfer-Encoding of
20
 * x-uuencode, a Content-Type of application-octet-stream, and a
21
 * Content-Disposition of 'attachment'.  It also expects a mode and filename to
22
 * initialize it, and adds 'filename' parts to the Content-Disposition and
23
 * 'name' to Content-Type.
24
 * 
25
 * @author Zaahid Bateson <[email protected]>
26
 */
27
class UUEncodedPart extends NonMimePart
28
{
29
    /**
30
     * @var int the unix file permission
31
     */
32
    protected $mode = null;
33
    
34
    /**
35
     * @var string the name of the file in the uuencoding 'header'.
36
     */
37
    protected $filename = null;
38
    
39
    /**
40
     * Initiates the UUEncodedPart with the passed mode and filename.
41
     * 
42
     * @param HeaderFactory $headerFactory
43
     * @param MimePartWriter $partWriter
44
     * @param int $mode the unix file mode
45
     * @param string $filename the filename
46
     */
47 1
    public function __construct(
48
        HeaderFactory $headerFactory,
49
        MimePartWriter $partWriter,
50
        $mode,
51
        $filename
52
    ) {
53 1
        parent::__construct($headerFactory, $partWriter);
54 1
        $this->mode = $mode;
55 1
        $this->filename = $filename;
56
        
57 1
        $this->setRawHeader(
58 1
            'Content-Type',
59 1
            'application/octet-stream; name="' . addcslashes($filename, '"') . '"'
60 1
        );
61 1
        $this->setRawHeader(
62 1
            'Content-Disposition',
63 1
            'attachment; filename="' . addcslashes($filename, '"') . '"'
64 1
        );
65 1
        $this->setRawHeader('Content-Transfer-Encoding', 'x-uuencode');
66 1
    }
67
    
68
    /**
69
     * Returns the file mode included in the uuencoded header for this part.
70
     * 
71
     * @return int
72
     */
73 1
    public function getUnixFileMode()
74
    {
75 1
        return $this->mode;
76
    }
77
    
78
    /**
79
     * Returns the filename included in the uuencoded header for this part.
80
     * 
81
     * @return string
82
     */
83 1
    public function getFilename()
84
    {
85 1
        return $this->filename;
86
    }
87
}
88