]> git.donarmstrong.com Git - roundcube.git/blob - program/include/rcube_mime_struct.php
Imported Upstream version 0.7
[roundcube.git] / program / include / rcube_mime_struct.php
1
2     function getStructurePartType($structure, $part)
3     {
4             $part_a = self::getPartArray($structure, $part);
5             if (!empty($part_a)) {
6                     if (is_array($part_a[0]))
7                 return 'multipart';
8                     else if ($part_a[0])
9                 return $part_a[0];
10             }
11
12         return 'other';
13     }
14
15     function getStructurePartEncoding($structure, $part)
16     {
17             $part_a = self::getPartArray($structure, $part);
18             if ($part_a) {
19                     if (!is_array($part_a[0]))
20                 return $part_a[5];
21             }
22
23         return '';
24     }
25
26     function getStructurePartCharset($structure, $part)
27     {
28             $part_a = self::getPartArray($structure, $part);
29             if ($part_a) {
30                     if (is_array($part_a[0]))
31                 return '';
32                     else {
33                             if (is_array($part_a[2])) {
34                                     $name = '';
35                                     while (list($key, $val) = each($part_a[2]))
36                         if (strcasecmp($val, 'charset') == 0)
37                             return $part_a[2][$key+1];
38                             }
39                     }
40             }
41
42         return '';
43     }
44
45     function getStructurePartArray($a, $part)
46     {
47             if (!is_array($a)) {
48             return false;
49         }
50             if (strpos($part, '.') > 0) {
51                     $original_part = $part;
52                     $pos = strpos($part, '.');
53                     $rest = substr($original_part, $pos+1);
54                     $part = substr($original_part, 0, $pos);
55                     if ((strcasecmp($a[0], 'message') == 0) && (strcasecmp($a[1], 'rfc822') == 0)) {
56                             $a = $a[8];
57                     }
58                     return self::getPartArray($a[$part-1], $rest);
59             }
60         else if ($part>0) {
61                     if (!is_array($a[0]) && (strcasecmp($a[0], 'message') == 0)
62                 && (strcasecmp($a[1], 'rfc822') == 0)) {
63                             $a = $a[8];
64                     }
65                     if (is_array($a[$part-1]))
66                 return $a[$part-1];
67                     else
68                 return $a;
69             }
70         else if (($part == 0) || (empty($part))) {
71                     return $a;
72             }
73     }