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_Imple_ImportEncryptKey extends Horde_Core_Ajax_Imple
24: {
25: 26: 27: 28: 29: 30:
31: public function __construct(array $params = array())
32: {
33: parent::__construct($params);
34: }
35:
36: 37:
38: protected function _attach($init)
39: {
40: if ($init) {
41: $this->_jsOnComplete('e.element().up("TR").remove()');
42: }
43:
44: return array(
45: 'mime_id' => $this->_params['mime_id'],
46: 'muid' => $this->_params['muid'],
47: 'type' => $this->_params['type']
48: );
49: }
50:
51: 52: 53: 54: 55: 56: 57: 58: 59:
60: protected function _handle(Horde_Variables $vars)
61: {
62: global $injector, $notification;
63:
64:
65: try {
66: $contents = $injector->getInstance('IMP_Factory_Contents')->create(new IMP_Indices_Mailbox($vars));
67: $mime_part = $contents->getMIMEPart($vars->mime_id);
68: if (empty($mime_part)) {
69: throw new IMP_Exception(_("Cannot retrieve public key from message."));
70: }
71:
72:
73: switch ($vars->type) {
74: case 'pgp':
75: $injector->getInstance('IMP_Crypt_Pgp')->addPublicKey($mime_part->getContents());
76: $notification->push(_("Successfully added public key from message."), 'horde.success');
77: break;
78:
79: case 'smime':
80: $stream = $vars->mime_id
81: ? $contents->getBodyPart($vars->mime_id, array('mimeheaders' => true, 'stream' => true))->data
82: : $contents->fullMessageText();
83: $raw_text = $mime_part->replaceEOL($stream, Horde_Mime_Part::RFC_EOL);
84:
85: $imp_smime = $injector->getInstance('IMP_Crypt_Smime');
86: $sig_result = $imp_smime->verifySignature($raw_text);
87: $imp_smime->addPublicKey($sig_result->cert);
88: $notification->push(_("Successfully added certificate from message."), 'horde.success');
89: break;
90: }
91: } catch (Exception $e) {
92: $notification->push($e, 'horde.error');
93: return false;
94: }
95:
96: return true;
97: }
98:
99: }
100: