-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmailvelope_client.php
More file actions
61 lines (57 loc) · 1.84 KB
/
mailvelope_client.php
File metadata and controls
61 lines (57 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
/**
* A client for mailvelopes client-API.
*
* @copyright Copyright (c) 2015 Posteo e.K <https://posteo.de>
* @license GNU GPLv3+
*/
class mailvelope_client extends rcube_plugin {
public function init() {
$rcmail = rcmail::get_instance();
$this->load_config();
$rcmail->output->set_env('mailvelope_client_pubkeyapi_url', $rcmail->config->get('mailvelope_client_pubkeyapi_url', 'https://api.posteo.de/v1/public_keys?type=open_pgp'));
$this->include_script('mailvelope_client.js');
$this->add_texts('localization', true);
$this->add_hook('message_before_send', array($this, 'mailvelope'));
}
public function mailvelope($args) {
if ($_POST['mailvelope_pgp_mime'] == '1') {
$ciphertext = $args['message']->getMessageBody();
// Delete body, else the lib won't add our attachments.
$args['message']->setTXTBody('');
// Make the message pgp/mime.
$res = $args['message']->addAttachment(
'Version: 1',
'application/pgp-encrypted',
'OpenPGP-version-information.txt',
false,
'7bit'
);
$this->log_result('Adding version-information failed', $res);
$res = $args['message']->addAttachment(
$ciphertext,
'application/octet-stream',
'encrypted.asc',
false,
'7bit',
'inline'
);
$this->log_result('Adding ciphertext failed', $res);
$res = $args['message']->setContentType(
'multipart/encrypted',
array(
'protocol' => 'application/pgp-encrypted'
)
);
$this->log_result('Changing content-type failed', $res);
$res = null;
}
return $args;
}
private function log_result($text, $res) {
if ($res != true) {
write_log('errors', "$text:");
write_log('errors', $res);
}
}
}