1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12:
13:
14: 15: 16: 17: 18: 19: 20: 21: 22:
23: class IMP_Ajax_Application_Compose
24: {
25: 26: 27: 28: 29:
30: public $forward_map = array(
31: 'editasnew' => IMP_Compose::EDITASNEW,
32: 'forward_attach' => IMP_Compose::FORWARD_ATTACH,
33: 'forward_auto' => IMP_Compose::FORWARD_AUTO,
34: 'forward_body' => IMP_Compose::FORWARD_BODY,
35: 'forward_both' => IMP_Compose::FORWARD_BOTH
36: );
37:
38: 39: 40: 41: 42:
43: public $reply_map = array(
44: 'reply' => IMP_Compose::REPLY_SENDER,
45: 'reply_all' => IMP_Compose::REPLY_ALL,
46: 'reply_auto' => IMP_Compose::REPLY_AUTO,
47: 'reply_list' => IMP_Compose::REPLY_LIST
48: );
49:
50: 51: 52: 53: 54:
55: protected $_compose;
56:
57: 58: 59: 60: 61:
62: protected $_type;
63:
64: 65: 66: 67: 68: 69:
70: public function __construct(IMP_Compose $ob, $type = null)
71: {
72: $this->_composeOb = $ob;
73: $this->_type = $type;
74: }
75:
76: 77:
78: public function getResponse($result)
79: {
80: $ob = $this->getBaseResponse($result);
81:
82: $ob->body = $result['body'];
83: $ob->format = $result['format'];
84: $ob->identity = $result['identity'];
85:
86: if (!empty($result['attach'])) {
87: $ob->opts->attach = 1;
88: }
89:
90: if ($search = array_search($result['type'], $this->reply_map)) {
91: if ($this->_type == 'reply_auto') {
92: $ob->opts->auto = $search;
93:
94: if (isset($result['reply_list_id'])) {
95: $ob->opts->reply_list_id = $result['reply_list_id'];
96: }
97: if (isset($result['reply_recip'])) {
98: $ob->opts->reply_recip = $result['reply_recip'];
99: }
100: }
101:
102: if (!empty($result['lang'])) {
103: $ob->opts->reply_lang = array_values($result['lang']);
104: }
105:
106: $ob->opts->focus = 'composeMessage';
107: } elseif ($search = array_search($result['type'], $this->forward_map)) {
108: if ($this->_type == 'forward_auto') {
109: $ob->opts->auto = $search;
110: }
111: } else {
112: $ob->opts->priority = $result['priority'];
113: $ob->opts->readreceipt = $result['readreceipt'];
114: }
115:
116: return $ob;
117: }
118:
119: 120:
121: public function getBaseResponse($result = array())
122: {
123: $ob = new stdClass;
124: $ob->body = '';
125: $ob->opts = new stdClass;
126: $ob->subject = isset($result['subject'])
127: ? $result['subject']
128: : '';
129: $ob->type = $this->_type;
130:
131: if (isset($result['addr'])) {
132: $ob->addr = array(
133: 'to' => array_map('strval', $result['addr']['to']->base_addresses),
134: 'cc' => array_map('strval', $result['addr']['cc']->base_addresses),
135: 'bcc' => array_map('strval', $result['addr']['bcc']->base_addresses),
136: );
137: }
138:
139: return $ob;
140: }
141:
142: }
143: