1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12:
13:
14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24:
25: class IMP
26: {
27:
28: const ENCRYPT_NONE = 'encrypt_none';
29:
30:
31: const MAILBOX_START_FIRSTUNSEEN = 1;
32: const MAILBOX_START_LASTUNSEEN = 2;
33: const MAILBOX_START_FIRSTPAGE = 3;
34: const MAILBOX_START_LASTPAGE = 4;
35:
36:
37: const NOTEPAD_EDIT = "notepad\0";
38: const TASKLIST_EDIT = "tasklist\0";
39:
40:
41: const INITIAL_FOLDERS = "initial\0folders";
42:
43:
44: const IMAP_SORT_DATE = 100;
45:
46: 47: 48: 49: 50: 51: 52:
53: public static function filterText($text)
54: {
55: global $injector, $prefs;
56:
57: if ($prefs->getValue('filtering') && strlen($text)) {
58: try {
59: return $injector->getInstance('Horde_Core_Factory_TextFilter')->filter(
60: $text,
61: 'words',
62: $injector->getInstance('Horde_Core_Hooks')->callHook('msg_filter', 'imp')
63: );
64: } catch (Horde_Exception_HookNotSet $e) {}
65: }
66:
67: return $text;
68: }
69:
70: 71: 72: 73: 74: 75:
76: public static function sizeFormat($size)
77: {
78: return ($size >= 1048576)
79: ? sprintf(_("%s MB"), self::numberFormat($size / 1048576, 1))
80: : sprintf(_("%s KB"), self::numberFormat($size / 1024, 0));
81: }
82:
83: 84: 85: 86: 87: 88: 89: 90:
91: public static function numberFormat($number, $decimals)
92: {
93: $localeinfo = Horde_Nls::getLocaleInfo();
94:
95: return str_replace(
96: array('X', 'Y'),
97: array($localeinfo['decimal_point'], $localeinfo['thousands_sep']),
98: number_format($decimals ? $number : ceil($number), $decimals, 'X', 'Y')
99: );
100: }
101:
102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112:
113: public static function parseAddressList($in, array $opts = array())
114: {
115: $md = $GLOBALS['injector']->getInstance('IMP_Factory_Imap')->create()->config->maildomain;
116:
117: if ($in instanceof Horde_Mail_Rfc822_List) {
118: $res = clone $in;
119: foreach ($res->raw_addresses as $val) {
120: if (is_null($val->host)) {
121: $val->host = $md;
122: }
123: }
124: } else {
125: $rfc822 = $GLOBALS['injector']->getInstance('Horde_Mail_Rfc822');
126: $res = $rfc822->parseAddressList($in, array_merge(array(
127: 'default_domain' => $md,
128: 'validate' => false
129: ), $opts));
130: }
131:
132: $res->setIteratorFilter(Horde_Mail_Rfc822_List::HIDE_GROUPS);
133:
134: return $res;
135: }
136:
137: 138: 139: 140: 141: 142: 143:
144: public static function getInitialPage()
145: {
146: global $injector, $prefs, $registry;
147:
148: $init_url = $prefs->getValue('initial_page');
149: if (!$init_url ||
150: !$injector->getInstance('IMP_Factory_Imap')->create()->access(IMP_Imap::ACCESS_FOLDERS)) {
151: $init_url = 'INBOX';
152: }
153:
154: if ($init_url == IMP::INITIAL_FOLDERS) {
155: $mbox = null;
156: } else {
157: $mbox = IMP_Mailbox::get($init_url);
158: if (!$mbox->exists) {
159: $mbox = IMP_Mailbox::get('INBOX');
160: }
161: }
162:
163: $result = new stdClass;
164: $result->mbox = $mbox;
165:
166: switch ($registry->getView()) {
167: case Horde_Registry::VIEW_BASIC:
168: $result->url = is_null($mbox)
169: ? IMP_Basic_Folders::url()
170: : $mbox->url('mailbox');
171: break;
172:
173: case Horde_Registry::VIEW_DYNAMIC:
174: $result->url = IMP_Dynamic_Mailbox::url(array(
175: 'mailbox' => is_null($mbox) ? 'INBOX' : $mbox
176: ));
177: break;
178:
179: case Horde_Registry::VIEW_MINIMAL:
180: $result->url = is_null($mbox)
181: ? IMP_Minimal_Folders::url()
182: : IMP_Minimal_Mailbox::url(array('mailbox' => $mbox));
183: break;
184:
185: case Horde_Registry::VIEW_SMARTMOBILE:
186: $result->url = is_null($mbox)
187: ? Horde::url('smartmobile.php', true)
188: : $mbox->url('mailbox');
189: break;
190: }
191:
192: return $result;
193: }
194:
195: }
196: