Completed
Push — master ( aab6ae...03b37f )
by Zaahid
04:44
created

UUEncodedPart   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 3
c 2
b 1
f 0
lcom 0
cbo 1
dl 0
loc 56
rs 10

3 Methods

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