repo
stringlengths
6
63
path
stringlengths
5
140
func_name
stringlengths
3
151
original_string
stringlengths
84
13k
language
stringclasses
1 value
code
stringlengths
84
13k
code_tokens
list
docstring
stringlengths
3
47.2k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
91
247
partition
stringclasses
1 value
cloudcreativity/json-api
src/Http/Middleware/ParsesServerRequests.php
ParsesServerRequests.decodeDocument
protected function decodeDocument(ServerRequestInterface $serverRequest) { if (!http_contains_body($serverRequest)) { return null; } return new Document(json_decode((string) $serverRequest->getBody())); }
php
protected function decodeDocument(ServerRequestInterface $serverRequest) { if (!http_contains_body($serverRequest)) { return null; } return new Document(json_decode((string) $serverRequest->getBody())); }
[ "protected", "function", "decodeDocument", "(", "ServerRequestInterface", "$", "serverRequest", ")", "{", "if", "(", "!", "http_contains_body", "(", "$", "serverRequest", ")", ")", "{", "return", "null", ";", "}", "return", "new", "Document", "(", "json_decode", "(", "(", "string", ")", "$", "serverRequest", "->", "getBody", "(", ")", ")", ")", ";", "}" ]
Extract the JSON API document from the request. @param ServerRequestInterface $serverRequest @return Document|null @throws InvalidJsonException
[ "Extract", "the", "JSON", "API", "document", "from", "the", "request", "." ]
7bb556c8f67b7c2a248f7d5e45899e29e1e40930
https://github.com/cloudcreativity/json-api/blob/7bb556c8f67b7c2a248f7d5e45899e29e1e40930/src/Http/Middleware/ParsesServerRequests.php#L130-L137
train
cloudcreativity/json-api
src/Http/Middleware/ParsesServerRequests.php
ParsesServerRequests.isExpectingDocument
protected function isExpectingDocument(InboundRequestInterface $request) { return $request->isCreateResource() || $request->isUpdateResource() || $request->isReplaceRelationship() || $request->isAddToRelationship() || $request->isRemoveFromRelationship(); }
php
protected function isExpectingDocument(InboundRequestInterface $request) { return $request->isCreateResource() || $request->isUpdateResource() || $request->isReplaceRelationship() || $request->isAddToRelationship() || $request->isRemoveFromRelationship(); }
[ "protected", "function", "isExpectingDocument", "(", "InboundRequestInterface", "$", "request", ")", "{", "return", "$", "request", "->", "isCreateResource", "(", ")", "||", "$", "request", "->", "isUpdateResource", "(", ")", "||", "$", "request", "->", "isReplaceRelationship", "(", ")", "||", "$", "request", "->", "isAddToRelationship", "(", ")", "||", "$", "request", "->", "isRemoveFromRelationship", "(", ")", ";", "}" ]
Is a document expected for the supplied request? If the JSON API request is any of the following, a JSON API document is expected to be set on the request: - Create resource - Update resource - Replace resource relationship - Add to resource relationship - Remove from resource relationship @param InboundRequestInterface $request @return bool
[ "Is", "a", "document", "expected", "for", "the", "supplied", "request?" ]
7bb556c8f67b7c2a248f7d5e45899e29e1e40930
https://github.com/cloudcreativity/json-api/blob/7bb556c8f67b7c2a248f7d5e45899e29e1e40930/src/Http/Middleware/ParsesServerRequests.php#L168-L175
train
cloudcreativity/json-api
src/Exceptions/MutableErrorCollection.php
MutableErrorCollection.getHttpStatus
public function getHttpStatus($default = null) { $default = $default ?: JsonApiException::DEFAULT_HTTP_CODE; $request = null; $internal = null; /** @var MutableErrorInterface $error */ foreach ($this as $error) { $status = $error->getStatus(); if (400 <= $status && 499 >= $status) { $request = is_null($request) ? $status : ($request == $status) ? $status : 400; } elseif (500 <= $status && 599 >= $status) { $internal = is_null($internal) ? $status : ($internal == $status) ? $status : 500; } } if (!$request && !$internal) { return $default; } elseif ($request && $internal) { return 500; } return $request ?: $internal; }
php
public function getHttpStatus($default = null) { $default = $default ?: JsonApiException::DEFAULT_HTTP_CODE; $request = null; $internal = null; /** @var MutableErrorInterface $error */ foreach ($this as $error) { $status = $error->getStatus(); if (400 <= $status && 499 >= $status) { $request = is_null($request) ? $status : ($request == $status) ? $status : 400; } elseif (500 <= $status && 599 >= $status) { $internal = is_null($internal) ? $status : ($internal == $status) ? $status : 500; } } if (!$request && !$internal) { return $default; } elseif ($request && $internal) { return 500; } return $request ?: $internal; }
[ "public", "function", "getHttpStatus", "(", "$", "default", "=", "null", ")", "{", "$", "default", "=", "$", "default", "?", ":", "JsonApiException", "::", "DEFAULT_HTTP_CODE", ";", "$", "request", "=", "null", ";", "$", "internal", "=", "null", ";", "/** @var MutableErrorInterface $error */", "foreach", "(", "$", "this", "as", "$", "error", ")", "{", "$", "status", "=", "$", "error", "->", "getStatus", "(", ")", ";", "if", "(", "400", "<=", "$", "status", "&&", "499", ">=", "$", "status", ")", "{", "$", "request", "=", "is_null", "(", "$", "request", ")", "?", "$", "status", ":", "(", "$", "request", "==", "$", "status", ")", "?", "$", "status", ":", "400", ";", "}", "elseif", "(", "500", "<=", "$", "status", "&&", "599", ">=", "$", "status", ")", "{", "$", "internal", "=", "is_null", "(", "$", "internal", ")", "?", "$", "status", ":", "(", "$", "internal", "==", "$", "status", ")", "?", "$", "status", ":", "500", ";", "}", "}", "if", "(", "!", "$", "request", "&&", "!", "$", "internal", ")", "{", "return", "$", "default", ";", "}", "elseif", "(", "$", "request", "&&", "$", "internal", ")", "{", "return", "500", ";", "}", "return", "$", "request", "?", ":", "$", "internal", ";", "}" ]
Get the most applicable HTTP status code. From the spec: When a server encounters multiple problems for a single request, the most generally applicable HTTP error code SHOULD be used in the response. For instance, 400 Bad Request might be appropriate for multiple 4xx errors or 500 Internal Server Error might be appropriate for multiple 5xx errors. @param string|int|null $default the default to use if an error status cannot be resolved. Defaults to 400 Bad Request @return string|int
[ "Get", "the", "most", "applicable", "HTTP", "status", "code", "." ]
7bb556c8f67b7c2a248f7d5e45899e29e1e40930
https://github.com/cloudcreativity/json-api/blob/7bb556c8f67b7c2a248f7d5e45899e29e1e40930/src/Exceptions/MutableErrorCollection.php#L119-L144
train
cloudcreativity/json-api
src/Resolver/NamespaceResolver.php
NamespaceResolver.resolve
protected function resolve($unit, $resourceType) { $resourceType = Str::classify($resourceType); return $this->append($resourceType . '\\' . $unit); }
php
protected function resolve($unit, $resourceType) { $resourceType = Str::classify($resourceType); return $this->append($resourceType . '\\' . $unit); }
[ "protected", "function", "resolve", "(", "$", "unit", ",", "$", "resourceType", ")", "{", "$", "resourceType", "=", "Str", "::", "classify", "(", "$", "resourceType", ")", ";", "return", "$", "this", "->", "append", "(", "$", "resourceType", ".", "'\\\\'", ".", "$", "unit", ")", ";", "}" ]
Convert the provided unit name and resource type into a fully qualified namespace. @param $unit @param $resourceType @return string
[ "Convert", "the", "provided", "unit", "name", "and", "resource", "type", "into", "a", "fully", "qualified", "namespace", "." ]
7bb556c8f67b7c2a248f7d5e45899e29e1e40930
https://github.com/cloudcreativity/json-api/blob/7bb556c8f67b7c2a248f7d5e45899e29e1e40930/src/Resolver/NamespaceResolver.php#L195-L200
train
cloudcreativity/json-api
src/Http/Middleware/AuthorizesRequests.php
AuthorizesRequests.authorize
protected function authorize( InboundRequestInterface $request, StoreInterface $store, AuthorizerInterface $authorizer ) { $result = $this->checkAuthorization($request, $store, $authorizer); if (true !== $result) { throw new AuthorizationException($result); } }
php
protected function authorize( InboundRequestInterface $request, StoreInterface $store, AuthorizerInterface $authorizer ) { $result = $this->checkAuthorization($request, $store, $authorizer); if (true !== $result) { throw new AuthorizationException($result); } }
[ "protected", "function", "authorize", "(", "InboundRequestInterface", "$", "request", ",", "StoreInterface", "$", "store", ",", "AuthorizerInterface", "$", "authorizer", ")", "{", "$", "result", "=", "$", "this", "->", "checkAuthorization", "(", "$", "request", ",", "$", "store", ",", "$", "authorizer", ")", ";", "if", "(", "true", "!==", "$", "result", ")", "{", "throw", "new", "AuthorizationException", "(", "$", "result", ")", ";", "}", "}" ]
Authorize the request or throw an exception @param InboundRequestInterface $request @param StoreInterface $store @param AuthorizerInterface $authorizer @throws AuthorizationException
[ "Authorize", "the", "request", "or", "throw", "an", "exception" ]
7bb556c8f67b7c2a248f7d5e45899e29e1e40930
https://github.com/cloudcreativity/json-api/blob/7bb556c8f67b7c2a248f7d5e45899e29e1e40930/src/Http/Middleware/AuthorizesRequests.php#L43-L53
train
cloudcreativity/json-api
src/Http/Middleware/NegotiatesContent.php
NegotiatesContent.doContentNegotiation
protected function doContentNegotiation( HttpFactoryInterface $httpFactory, ServerRequestInterface $request, CodecMatcherInterface $codecMatcher ) { $parser = $httpFactory->createHeaderParametersParser(); $checker = $httpFactory->createHeadersChecker($codecMatcher); $checker->checkHeaders($parser->parse($request, http_contains_body($request))); }
php
protected function doContentNegotiation( HttpFactoryInterface $httpFactory, ServerRequestInterface $request, CodecMatcherInterface $codecMatcher ) { $parser = $httpFactory->createHeaderParametersParser(); $checker = $httpFactory->createHeadersChecker($codecMatcher); $checker->checkHeaders($parser->parse($request, http_contains_body($request))); }
[ "protected", "function", "doContentNegotiation", "(", "HttpFactoryInterface", "$", "httpFactory", ",", "ServerRequestInterface", "$", "request", ",", "CodecMatcherInterface", "$", "codecMatcher", ")", "{", "$", "parser", "=", "$", "httpFactory", "->", "createHeaderParametersParser", "(", ")", ";", "$", "checker", "=", "$", "httpFactory", "->", "createHeadersChecker", "(", "$", "codecMatcher", ")", ";", "$", "checker", "->", "checkHeaders", "(", "$", "parser", "->", "parse", "(", "$", "request", ",", "http_contains_body", "(", "$", "request", ")", ")", ")", ";", "}" ]
Perform content negotiation. @param HttpFactoryInterface $httpFactory @param ServerRequestInterface $request @param CodecMatcherInterface $codecMatcher @throws JsonApiException @see http://jsonapi.org/format/#content-negotiation
[ "Perform", "content", "negotiation", "." ]
7bb556c8f67b7c2a248f7d5e45899e29e1e40930
https://github.com/cloudcreativity/json-api/blob/7bb556c8f67b7c2a248f7d5e45899e29e1e40930/src/Http/Middleware/NegotiatesContent.php#L44-L53
train
cloudcreativity/json-api
src/Http/Client/GuzzleClient.php
GuzzleClient.parseErrorResponse
private function parseErrorResponse(PsrRequest $request, BadResponseException $ex) { try { $response = $ex->getResponse(); $document = $response ? $this->factory->createDocumentObject($request, $response) : null; $errors = $document ? $document->getErrors() : []; $statusCode = $response ? $response->getStatusCode() : 0; } catch (Exception $e) { $errors = []; $statusCode = 0; } return new JsonApiException($errors, $statusCode, $ex); }
php
private function parseErrorResponse(PsrRequest $request, BadResponseException $ex) { try { $response = $ex->getResponse(); $document = $response ? $this->factory->createDocumentObject($request, $response) : null; $errors = $document ? $document->getErrors() : []; $statusCode = $response ? $response->getStatusCode() : 0; } catch (Exception $e) { $errors = []; $statusCode = 0; } return new JsonApiException($errors, $statusCode, $ex); }
[ "private", "function", "parseErrorResponse", "(", "PsrRequest", "$", "request", ",", "BadResponseException", "$", "ex", ")", "{", "try", "{", "$", "response", "=", "$", "ex", "->", "getResponse", "(", ")", ";", "$", "document", "=", "$", "response", "?", "$", "this", "->", "factory", "->", "createDocumentObject", "(", "$", "request", ",", "$", "response", ")", ":", "null", ";", "$", "errors", "=", "$", "document", "?", "$", "document", "->", "getErrors", "(", ")", ":", "[", "]", ";", "$", "statusCode", "=", "$", "response", "?", "$", "response", "->", "getStatusCode", "(", ")", ":", "0", ";", "}", "catch", "(", "Exception", "$", "e", ")", "{", "$", "errors", "=", "[", "]", ";", "$", "statusCode", "=", "0", ";", "}", "return", "new", "JsonApiException", "(", "$", "errors", ",", "$", "statusCode", ",", "$", "ex", ")", ";", "}" ]
Safely parse an error response. This method wraps decoding the body content of the provided exception, so that another exception is not thrown while trying to parse an existing exception. @param PsrRequest $request @param BadResponseException $ex @return JsonApiException
[ "Safely", "parse", "an", "error", "response", "." ]
7bb556c8f67b7c2a248f7d5e45899e29e1e40930
https://github.com/cloudcreativity/json-api/blob/7bb556c8f67b7c2a248f7d5e45899e29e1e40930/src/Http/Client/GuzzleClient.php#L205-L218
train
i-MSCP/roundcube
roundcubemail/plugins/acl/acl.php
acl.acl_autocomplete
function acl_autocomplete() { $this->load_config(); $search = rcube_utils::get_input_value('_search', rcube_utils::INPUT_GPC, true); $reqid = rcube_utils::get_input_value('_reqid', rcube_utils::INPUT_GPC); $users = array(); $keys = array(); if ($this->init_ldap()) { $max = (int) $this->rc->config->get('autocomplete_max', 15); $mode = (int) $this->rc->config->get('addressbook_search_mode'); $this->ldap->set_pagesize($max); $result = $this->ldap->search('*', $search, $mode); foreach ($result->records as $record) { $user = $record['uid']; if (is_array($user)) { $user = array_filter($user); $user = $user[0]; } if ($user) { $display = rcube_addressbook::compose_search_name($record); $user = array('name' => $user, 'display' => $display); $users[] = $user; $keys[] = $display ?: $user['name']; } } if ($this->rc->config->get('acl_groups')) { $prefix = $this->rc->config->get('acl_group_prefix'); $group_field = $this->rc->config->get('acl_group_field', 'name'); $result = $this->ldap->list_groups($search, $mode); foreach ($result as $record) { $group = $record['name']; $group_id = is_array($record[$group_field]) ? $record[$group_field][0] : $record[$group_field]; if ($group) { $users[] = array('name' => ($prefix ?: '') . $group_id, 'display' => $group, 'type' => 'group'); $keys[] = $group; } } } } if (count($users)) { // sort users index asort($keys, SORT_LOCALE_STRING); // re-sort users according to index foreach ($keys as $idx => $val) { $keys[$idx] = $users[$idx]; } $users = array_values($keys); } $this->rc->output->command('ksearch_query_results', $users, $search, $reqid); $this->rc->output->send(); }
php
function acl_autocomplete() { $this->load_config(); $search = rcube_utils::get_input_value('_search', rcube_utils::INPUT_GPC, true); $reqid = rcube_utils::get_input_value('_reqid', rcube_utils::INPUT_GPC); $users = array(); $keys = array(); if ($this->init_ldap()) { $max = (int) $this->rc->config->get('autocomplete_max', 15); $mode = (int) $this->rc->config->get('addressbook_search_mode'); $this->ldap->set_pagesize($max); $result = $this->ldap->search('*', $search, $mode); foreach ($result->records as $record) { $user = $record['uid']; if (is_array($user)) { $user = array_filter($user); $user = $user[0]; } if ($user) { $display = rcube_addressbook::compose_search_name($record); $user = array('name' => $user, 'display' => $display); $users[] = $user; $keys[] = $display ?: $user['name']; } } if ($this->rc->config->get('acl_groups')) { $prefix = $this->rc->config->get('acl_group_prefix'); $group_field = $this->rc->config->get('acl_group_field', 'name'); $result = $this->ldap->list_groups($search, $mode); foreach ($result as $record) { $group = $record['name']; $group_id = is_array($record[$group_field]) ? $record[$group_field][0] : $record[$group_field]; if ($group) { $users[] = array('name' => ($prefix ?: '') . $group_id, 'display' => $group, 'type' => 'group'); $keys[] = $group; } } } } if (count($users)) { // sort users index asort($keys, SORT_LOCALE_STRING); // re-sort users according to index foreach ($keys as $idx => $val) { $keys[$idx] = $users[$idx]; } $users = array_values($keys); } $this->rc->output->command('ksearch_query_results', $users, $search, $reqid); $this->rc->output->send(); }
[ "function", "acl_autocomplete", "(", ")", "{", "$", "this", "->", "load_config", "(", ")", ";", "$", "search", "=", "rcube_utils", "::", "get_input_value", "(", "'_search'", ",", "rcube_utils", "::", "INPUT_GPC", ",", "true", ")", ";", "$", "reqid", "=", "rcube_utils", "::", "get_input_value", "(", "'_reqid'", ",", "rcube_utils", "::", "INPUT_GPC", ")", ";", "$", "users", "=", "array", "(", ")", ";", "$", "keys", "=", "array", "(", ")", ";", "if", "(", "$", "this", "->", "init_ldap", "(", ")", ")", "{", "$", "max", "=", "(", "int", ")", "$", "this", "->", "rc", "->", "config", "->", "get", "(", "'autocomplete_max'", ",", "15", ")", ";", "$", "mode", "=", "(", "int", ")", "$", "this", "->", "rc", "->", "config", "->", "get", "(", "'addressbook_search_mode'", ")", ";", "$", "this", "->", "ldap", "->", "set_pagesize", "(", "$", "max", ")", ";", "$", "result", "=", "$", "this", "->", "ldap", "->", "search", "(", "'*'", ",", "$", "search", ",", "$", "mode", ")", ";", "foreach", "(", "$", "result", "->", "records", "as", "$", "record", ")", "{", "$", "user", "=", "$", "record", "[", "'uid'", "]", ";", "if", "(", "is_array", "(", "$", "user", ")", ")", "{", "$", "user", "=", "array_filter", "(", "$", "user", ")", ";", "$", "user", "=", "$", "user", "[", "0", "]", ";", "}", "if", "(", "$", "user", ")", "{", "$", "display", "=", "rcube_addressbook", "::", "compose_search_name", "(", "$", "record", ")", ";", "$", "user", "=", "array", "(", "'name'", "=>", "$", "user", ",", "'display'", "=>", "$", "display", ")", ";", "$", "users", "[", "]", "=", "$", "user", ";", "$", "keys", "[", "]", "=", "$", "display", "?", ":", "$", "user", "[", "'name'", "]", ";", "}", "}", "if", "(", "$", "this", "->", "rc", "->", "config", "->", "get", "(", "'acl_groups'", ")", ")", "{", "$", "prefix", "=", "$", "this", "->", "rc", "->", "config", "->", "get", "(", "'acl_group_prefix'", ")", ";", "$", "group_field", "=", "$", "this", "->", "rc", "->", "config", "->", "get", "(", "'acl_group_field'", ",", "'name'", ")", ";", "$", "result", "=", "$", "this", "->", "ldap", "->", "list_groups", "(", "$", "search", ",", "$", "mode", ")", ";", "foreach", "(", "$", "result", "as", "$", "record", ")", "{", "$", "group", "=", "$", "record", "[", "'name'", "]", ";", "$", "group_id", "=", "is_array", "(", "$", "record", "[", "$", "group_field", "]", ")", "?", "$", "record", "[", "$", "group_field", "]", "[", "0", "]", ":", "$", "record", "[", "$", "group_field", "]", ";", "if", "(", "$", "group", ")", "{", "$", "users", "[", "]", "=", "array", "(", "'name'", "=>", "(", "$", "prefix", "?", ":", "''", ")", ".", "$", "group_id", ",", "'display'", "=>", "$", "group", ",", "'type'", "=>", "'group'", ")", ";", "$", "keys", "[", "]", "=", "$", "group", ";", "}", "}", "}", "}", "if", "(", "count", "(", "$", "users", ")", ")", "{", "// sort users index", "asort", "(", "$", "keys", ",", "SORT_LOCALE_STRING", ")", ";", "// re-sort users according to index", "foreach", "(", "$", "keys", "as", "$", "idx", "=>", "$", "val", ")", "{", "$", "keys", "[", "$", "idx", "]", "=", "$", "users", "[", "$", "idx", "]", ";", "}", "$", "users", "=", "array_values", "(", "$", "keys", ")", ";", "}", "$", "this", "->", "rc", "->", "output", "->", "command", "(", "'ksearch_query_results'", ",", "$", "users", ",", "$", "search", ",", "$", "reqid", ")", ";", "$", "this", "->", "rc", "->", "output", "->", "send", "(", ")", ";", "}" ]
Handler for user login autocomplete request
[ "Handler", "for", "user", "login", "autocomplete", "request" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/plugins/acl/acl.php#L82-L143
train
i-MSCP/roundcube
roundcubemail/plugins/acl/acl.php
acl.folder_form
function folder_form($args) { $mbox_imap = $args['options']['name']; $myrights = $args['options']['rights']; // Edited folder name (empty in create-folder mode) if (!strlen($mbox_imap)) { return $args; } /* // Do nothing on protected folders (?) if ($args['options']['protected']) { return $args; } */ // Get MYRIGHTS if (empty($myrights)) { return $args; } // Load localization and include scripts $this->load_config(); $this->specials = $this->rc->config->get('acl_specials', $this->specials); $this->add_texts('localization/', array('deleteconfirm', 'norights', 'nouser', 'deleting', 'saving', 'newuser', 'editperms')); $this->rc->output->add_label('save', 'cancel'); $this->include_script('acl.js'); $this->rc->output->include_script('list.js'); $this->include_stylesheet($this->local_skin_path().'/acl.css'); // add Info fieldset if it doesn't exist if (!isset($args['form']['props']['fieldsets']['info'])) $args['form']['props']['fieldsets']['info'] = array( 'name' => $this->rc->gettext('info'), 'content' => array()); // Display folder rights to 'Info' fieldset $args['form']['props']['fieldsets']['info']['content']['myrights'] = array( 'label' => rcube::Q($this->gettext('myrights')), 'value' => $this->acl2text($myrights) ); // Return if not folder admin if (!in_array('a', $myrights)) { return $args; } // The 'Sharing' tab $this->mbox = $mbox_imap; $this->rc->output->set_env('acl_users_source', (bool) $this->rc->config->get('acl_users_source')); $this->rc->output->set_env('mailbox', $mbox_imap); $this->rc->output->add_handlers(array( 'acltable' => array($this, 'templ_table'), 'acluser' => array($this, 'templ_user'), 'aclrights' => array($this, 'templ_rights'), )); $this->rc->output->set_env('autocomplete_max', (int)$this->rc->config->get('autocomplete_max', 15)); $this->rc->output->set_env('autocomplete_min_length', $this->rc->config->get('autocomplete_min_length')); $this->rc->output->add_label('autocompletechars', 'autocompletemore'); $args['form']['sharing'] = array( 'name' => rcube::Q($this->gettext('sharing')), 'content' => $this->rc->output->parse('acl.table', false, false), ); return $args; }
php
function folder_form($args) { $mbox_imap = $args['options']['name']; $myrights = $args['options']['rights']; // Edited folder name (empty in create-folder mode) if (!strlen($mbox_imap)) { return $args; } /* // Do nothing on protected folders (?) if ($args['options']['protected']) { return $args; } */ // Get MYRIGHTS if (empty($myrights)) { return $args; } // Load localization and include scripts $this->load_config(); $this->specials = $this->rc->config->get('acl_specials', $this->specials); $this->add_texts('localization/', array('deleteconfirm', 'norights', 'nouser', 'deleting', 'saving', 'newuser', 'editperms')); $this->rc->output->add_label('save', 'cancel'); $this->include_script('acl.js'); $this->rc->output->include_script('list.js'); $this->include_stylesheet($this->local_skin_path().'/acl.css'); // add Info fieldset if it doesn't exist if (!isset($args['form']['props']['fieldsets']['info'])) $args['form']['props']['fieldsets']['info'] = array( 'name' => $this->rc->gettext('info'), 'content' => array()); // Display folder rights to 'Info' fieldset $args['form']['props']['fieldsets']['info']['content']['myrights'] = array( 'label' => rcube::Q($this->gettext('myrights')), 'value' => $this->acl2text($myrights) ); // Return if not folder admin if (!in_array('a', $myrights)) { return $args; } // The 'Sharing' tab $this->mbox = $mbox_imap; $this->rc->output->set_env('acl_users_source', (bool) $this->rc->config->get('acl_users_source')); $this->rc->output->set_env('mailbox', $mbox_imap); $this->rc->output->add_handlers(array( 'acltable' => array($this, 'templ_table'), 'acluser' => array($this, 'templ_user'), 'aclrights' => array($this, 'templ_rights'), )); $this->rc->output->set_env('autocomplete_max', (int)$this->rc->config->get('autocomplete_max', 15)); $this->rc->output->set_env('autocomplete_min_length', $this->rc->config->get('autocomplete_min_length')); $this->rc->output->add_label('autocompletechars', 'autocompletemore'); $args['form']['sharing'] = array( 'name' => rcube::Q($this->gettext('sharing')), 'content' => $this->rc->output->parse('acl.table', false, false), ); return $args; }
[ "function", "folder_form", "(", "$", "args", ")", "{", "$", "mbox_imap", "=", "$", "args", "[", "'options'", "]", "[", "'name'", "]", ";", "$", "myrights", "=", "$", "args", "[", "'options'", "]", "[", "'rights'", "]", ";", "// Edited folder name (empty in create-folder mode)", "if", "(", "!", "strlen", "(", "$", "mbox_imap", ")", ")", "{", "return", "$", "args", ";", "}", "/*\n // Do nothing on protected folders (?)\n if ($args['options']['protected']) {\n return $args;\n }\n*/", "// Get MYRIGHTS", "if", "(", "empty", "(", "$", "myrights", ")", ")", "{", "return", "$", "args", ";", "}", "// Load localization and include scripts", "$", "this", "->", "load_config", "(", ")", ";", "$", "this", "->", "specials", "=", "$", "this", "->", "rc", "->", "config", "->", "get", "(", "'acl_specials'", ",", "$", "this", "->", "specials", ")", ";", "$", "this", "->", "add_texts", "(", "'localization/'", ",", "array", "(", "'deleteconfirm'", ",", "'norights'", ",", "'nouser'", ",", "'deleting'", ",", "'saving'", ",", "'newuser'", ",", "'editperms'", ")", ")", ";", "$", "this", "->", "rc", "->", "output", "->", "add_label", "(", "'save'", ",", "'cancel'", ")", ";", "$", "this", "->", "include_script", "(", "'acl.js'", ")", ";", "$", "this", "->", "rc", "->", "output", "->", "include_script", "(", "'list.js'", ")", ";", "$", "this", "->", "include_stylesheet", "(", "$", "this", "->", "local_skin_path", "(", ")", ".", "'/acl.css'", ")", ";", "// add Info fieldset if it doesn't exist", "if", "(", "!", "isset", "(", "$", "args", "[", "'form'", "]", "[", "'props'", "]", "[", "'fieldsets'", "]", "[", "'info'", "]", ")", ")", "$", "args", "[", "'form'", "]", "[", "'props'", "]", "[", "'fieldsets'", "]", "[", "'info'", "]", "=", "array", "(", "'name'", "=>", "$", "this", "->", "rc", "->", "gettext", "(", "'info'", ")", ",", "'content'", "=>", "array", "(", ")", ")", ";", "// Display folder rights to 'Info' fieldset", "$", "args", "[", "'form'", "]", "[", "'props'", "]", "[", "'fieldsets'", "]", "[", "'info'", "]", "[", "'content'", "]", "[", "'myrights'", "]", "=", "array", "(", "'label'", "=>", "rcube", "::", "Q", "(", "$", "this", "->", "gettext", "(", "'myrights'", ")", ")", ",", "'value'", "=>", "$", "this", "->", "acl2text", "(", "$", "myrights", ")", ")", ";", "// Return if not folder admin", "if", "(", "!", "in_array", "(", "'a'", ",", "$", "myrights", ")", ")", "{", "return", "$", "args", ";", "}", "// The 'Sharing' tab", "$", "this", "->", "mbox", "=", "$", "mbox_imap", ";", "$", "this", "->", "rc", "->", "output", "->", "set_env", "(", "'acl_users_source'", ",", "(", "bool", ")", "$", "this", "->", "rc", "->", "config", "->", "get", "(", "'acl_users_source'", ")", ")", ";", "$", "this", "->", "rc", "->", "output", "->", "set_env", "(", "'mailbox'", ",", "$", "mbox_imap", ")", ";", "$", "this", "->", "rc", "->", "output", "->", "add_handlers", "(", "array", "(", "'acltable'", "=>", "array", "(", "$", "this", ",", "'templ_table'", ")", ",", "'acluser'", "=>", "array", "(", "$", "this", ",", "'templ_user'", ")", ",", "'aclrights'", "=>", "array", "(", "$", "this", ",", "'templ_rights'", ")", ",", ")", ")", ";", "$", "this", "->", "rc", "->", "output", "->", "set_env", "(", "'autocomplete_max'", ",", "(", "int", ")", "$", "this", "->", "rc", "->", "config", "->", "get", "(", "'autocomplete_max'", ",", "15", ")", ")", ";", "$", "this", "->", "rc", "->", "output", "->", "set_env", "(", "'autocomplete_min_length'", ",", "$", "this", "->", "rc", "->", "config", "->", "get", "(", "'autocomplete_min_length'", ")", ")", ";", "$", "this", "->", "rc", "->", "output", "->", "add_label", "(", "'autocompletechars'", ",", "'autocompletemore'", ")", ";", "$", "args", "[", "'form'", "]", "[", "'sharing'", "]", "=", "array", "(", "'name'", "=>", "rcube", "::", "Q", "(", "$", "this", "->", "gettext", "(", "'sharing'", ")", ")", ",", "'content'", "=>", "$", "this", "->", "rc", "->", "output", "->", "parse", "(", "'acl.table'", ",", "false", ",", "false", ")", ",", ")", ";", "return", "$", "args", ";", "}" ]
Handler for 'folder_form' hook @param array $args Hook arguments array (form data) @return array Hook arguments array
[ "Handler", "for", "folder_form", "hook" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/plugins/acl/acl.php#L152-L219
train
i-MSCP/roundcube
roundcubemail/plugins/acl/acl.php
acl.action_delete
private function action_delete() { $mbox = trim(rcube_utils::get_input_value('_mbox', rcube_utils::INPUT_POST, true)); //UTF7-IMAP $user = trim(rcube_utils::get_input_value('_user', rcube_utils::INPUT_POST)); $user = explode(',', $user); foreach ($user as $u) { $u = trim($u); if ($this->rc->storage->delete_acl($mbox, $u)) { $this->rc->output->command('acl_remove_row', rcube_utils::html_identifier($u)); } else { $error = true; } } if (!$error) { $this->rc->output->show_message('acl.deletesuccess', 'confirmation'); } else { $this->rc->output->show_message('acl.deleteerror', 'error'); } }
php
private function action_delete() { $mbox = trim(rcube_utils::get_input_value('_mbox', rcube_utils::INPUT_POST, true)); //UTF7-IMAP $user = trim(rcube_utils::get_input_value('_user', rcube_utils::INPUT_POST)); $user = explode(',', $user); foreach ($user as $u) { $u = trim($u); if ($this->rc->storage->delete_acl($mbox, $u)) { $this->rc->output->command('acl_remove_row', rcube_utils::html_identifier($u)); } else { $error = true; } } if (!$error) { $this->rc->output->show_message('acl.deletesuccess', 'confirmation'); } else { $this->rc->output->show_message('acl.deleteerror', 'error'); } }
[ "private", "function", "action_delete", "(", ")", "{", "$", "mbox", "=", "trim", "(", "rcube_utils", "::", "get_input_value", "(", "'_mbox'", ",", "rcube_utils", "::", "INPUT_POST", ",", "true", ")", ")", ";", "//UTF7-IMAP", "$", "user", "=", "trim", "(", "rcube_utils", "::", "get_input_value", "(", "'_user'", ",", "rcube_utils", "::", "INPUT_POST", ")", ")", ";", "$", "user", "=", "explode", "(", "','", ",", "$", "user", ")", ";", "foreach", "(", "$", "user", "as", "$", "u", ")", "{", "$", "u", "=", "trim", "(", "$", "u", ")", ";", "if", "(", "$", "this", "->", "rc", "->", "storage", "->", "delete_acl", "(", "$", "mbox", ",", "$", "u", ")", ")", "{", "$", "this", "->", "rc", "->", "output", "->", "command", "(", "'acl_remove_row'", ",", "rcube_utils", "::", "html_identifier", "(", "$", "u", ")", ")", ";", "}", "else", "{", "$", "error", "=", "true", ";", "}", "}", "if", "(", "!", "$", "error", ")", "{", "$", "this", "->", "rc", "->", "output", "->", "show_message", "(", "'acl.deletesuccess'", ",", "'confirmation'", ")", ";", "}", "else", "{", "$", "this", "->", "rc", "->", "output", "->", "show_message", "(", "'acl.deleteerror'", ",", "'error'", ")", ";", "}", "}" ]
Handler for ACL delete action
[ "Handler", "for", "ACL", "delete", "action" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/plugins/acl/acl.php#L535-L558
train
i-MSCP/roundcube
roundcubemail/plugins/acl/acl.php
acl.get_realm
private function get_realm() { // When user enters a username without domain part, realm // allows to add it to the username (and display correct username in the table) if (isset($_SESSION['acl_username_realm'])) { return $_SESSION['acl_username_realm']; } // find realm in username of logged user (?) list($name, $domain) = explode('@', $_SESSION['username']); // Use (always existent) ACL entry on the INBOX for the user to determine // whether or not the user ID in ACL entries need to be qualified and how // they would need to be qualified. if (empty($domain)) { $acl = $this->rc->storage->get_acl('INBOX'); if (is_array($acl)) { $regexp = '/^' . preg_quote($_SESSION['username'], '/') . '@(.*)$/'; foreach (array_keys($acl) as $name) { if (preg_match($regexp, $name, $matches)) { $domain = $matches[1]; break; } } } } return $_SESSION['acl_username_realm'] = $domain; }
php
private function get_realm() { // When user enters a username without domain part, realm // allows to add it to the username (and display correct username in the table) if (isset($_SESSION['acl_username_realm'])) { return $_SESSION['acl_username_realm']; } // find realm in username of logged user (?) list($name, $domain) = explode('@', $_SESSION['username']); // Use (always existent) ACL entry on the INBOX for the user to determine // whether or not the user ID in ACL entries need to be qualified and how // they would need to be qualified. if (empty($domain)) { $acl = $this->rc->storage->get_acl('INBOX'); if (is_array($acl)) { $regexp = '/^' . preg_quote($_SESSION['username'], '/') . '@(.*)$/'; foreach (array_keys($acl) as $name) { if (preg_match($regexp, $name, $matches)) { $domain = $matches[1]; break; } } } } return $_SESSION['acl_username_realm'] = $domain; }
[ "private", "function", "get_realm", "(", ")", "{", "// When user enters a username without domain part, realm", "// allows to add it to the username (and display correct username in the table)", "if", "(", "isset", "(", "$", "_SESSION", "[", "'acl_username_realm'", "]", ")", ")", "{", "return", "$", "_SESSION", "[", "'acl_username_realm'", "]", ";", "}", "// find realm in username of logged user (?)", "list", "(", "$", "name", ",", "$", "domain", ")", "=", "explode", "(", "'@'", ",", "$", "_SESSION", "[", "'username'", "]", ")", ";", "// Use (always existent) ACL entry on the INBOX for the user to determine", "// whether or not the user ID in ACL entries need to be qualified and how", "// they would need to be qualified.", "if", "(", "empty", "(", "$", "domain", ")", ")", "{", "$", "acl", "=", "$", "this", "->", "rc", "->", "storage", "->", "get_acl", "(", "'INBOX'", ")", ";", "if", "(", "is_array", "(", "$", "acl", ")", ")", "{", "$", "regexp", "=", "'/^'", ".", "preg_quote", "(", "$", "_SESSION", "[", "'username'", "]", ",", "'/'", ")", ".", "'@(.*)$/'", ";", "foreach", "(", "array_keys", "(", "$", "acl", ")", "as", "$", "name", ")", "{", "if", "(", "preg_match", "(", "$", "regexp", ",", "$", "name", ",", "$", "matches", ")", ")", "{", "$", "domain", "=", "$", "matches", "[", "1", "]", ";", "break", ";", "}", "}", "}", "}", "return", "$", "_SESSION", "[", "'acl_username_realm'", "]", "=", "$", "domain", ";", "}" ]
Username realm detection. @return string Username realm (domain)
[ "Username", "realm", "detection", "." ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/plugins/acl/acl.php#L673-L702
train
i-MSCP/roundcube
roundcubemail/plugins/acl/acl.php
acl.init_ldap
private function init_ldap() { if ($this->ldap) { return $this->ldap->ready; } // get LDAP config $config = $this->rc->config->get('acl_users_source'); if (empty($config)) { return false; } // not an array, use configured ldap_public source if (!is_array($config)) { $ldap_config = (array) $this->rc->config->get('ldap_public'); $config = $ldap_config[$config]; } $uid_field = $this->rc->config->get('acl_users_field', 'mail'); $filter = $this->rc->config->get('acl_users_filter'); if (empty($uid_field) || empty($config)) { return false; } // get name attribute if (!empty($config['fieldmap'])) { $name_field = $config['fieldmap']['name']; } // ... no fieldmap, use the old method if (empty($name_field)) { $name_field = $config['name_field']; } // add UID field to fieldmap, so it will be returned in a record with name $config['fieldmap']['name'] = $name_field; $config['fieldmap']['uid'] = $uid_field; // search in UID and name fields // $name_field can be in a form of <field>:<modifier> (#1490591) $name_field = preg_replace('/:.*$/', '', $name_field); $search = array_unique(array($name_field, $uid_field)); $config['search_fields'] = $search; $config['required_fields'] = array($uid_field); // set search filter if ($filter) { $config['filter'] = $filter; } // disable vlv $config['vlv'] = false; // Initialize LDAP connection $this->ldap = new rcube_ldap($config, $this->rc->config->get('ldap_debug'), $this->rc->config->mail_domain($_SESSION['imap_host'])); return $this->ldap->ready; }
php
private function init_ldap() { if ($this->ldap) { return $this->ldap->ready; } // get LDAP config $config = $this->rc->config->get('acl_users_source'); if (empty($config)) { return false; } // not an array, use configured ldap_public source if (!is_array($config)) { $ldap_config = (array) $this->rc->config->get('ldap_public'); $config = $ldap_config[$config]; } $uid_field = $this->rc->config->get('acl_users_field', 'mail'); $filter = $this->rc->config->get('acl_users_filter'); if (empty($uid_field) || empty($config)) { return false; } // get name attribute if (!empty($config['fieldmap'])) { $name_field = $config['fieldmap']['name']; } // ... no fieldmap, use the old method if (empty($name_field)) { $name_field = $config['name_field']; } // add UID field to fieldmap, so it will be returned in a record with name $config['fieldmap']['name'] = $name_field; $config['fieldmap']['uid'] = $uid_field; // search in UID and name fields // $name_field can be in a form of <field>:<modifier> (#1490591) $name_field = preg_replace('/:.*$/', '', $name_field); $search = array_unique(array($name_field, $uid_field)); $config['search_fields'] = $search; $config['required_fields'] = array($uid_field); // set search filter if ($filter) { $config['filter'] = $filter; } // disable vlv $config['vlv'] = false; // Initialize LDAP connection $this->ldap = new rcube_ldap($config, $this->rc->config->get('ldap_debug'), $this->rc->config->mail_domain($_SESSION['imap_host'])); return $this->ldap->ready; }
[ "private", "function", "init_ldap", "(", ")", "{", "if", "(", "$", "this", "->", "ldap", ")", "{", "return", "$", "this", "->", "ldap", "->", "ready", ";", "}", "// get LDAP config", "$", "config", "=", "$", "this", "->", "rc", "->", "config", "->", "get", "(", "'acl_users_source'", ")", ";", "if", "(", "empty", "(", "$", "config", ")", ")", "{", "return", "false", ";", "}", "// not an array, use configured ldap_public source", "if", "(", "!", "is_array", "(", "$", "config", ")", ")", "{", "$", "ldap_config", "=", "(", "array", ")", "$", "this", "->", "rc", "->", "config", "->", "get", "(", "'ldap_public'", ")", ";", "$", "config", "=", "$", "ldap_config", "[", "$", "config", "]", ";", "}", "$", "uid_field", "=", "$", "this", "->", "rc", "->", "config", "->", "get", "(", "'acl_users_field'", ",", "'mail'", ")", ";", "$", "filter", "=", "$", "this", "->", "rc", "->", "config", "->", "get", "(", "'acl_users_filter'", ")", ";", "if", "(", "empty", "(", "$", "uid_field", ")", "||", "empty", "(", "$", "config", ")", ")", "{", "return", "false", ";", "}", "// get name attribute", "if", "(", "!", "empty", "(", "$", "config", "[", "'fieldmap'", "]", ")", ")", "{", "$", "name_field", "=", "$", "config", "[", "'fieldmap'", "]", "[", "'name'", "]", ";", "}", "// ... no fieldmap, use the old method", "if", "(", "empty", "(", "$", "name_field", ")", ")", "{", "$", "name_field", "=", "$", "config", "[", "'name_field'", "]", ";", "}", "// add UID field to fieldmap, so it will be returned in a record with name", "$", "config", "[", "'fieldmap'", "]", "[", "'name'", "]", "=", "$", "name_field", ";", "$", "config", "[", "'fieldmap'", "]", "[", "'uid'", "]", "=", "$", "uid_field", ";", "// search in UID and name fields", "// $name_field can be in a form of <field>:<modifier> (#1490591)", "$", "name_field", "=", "preg_replace", "(", "'/:.*$/'", ",", "''", ",", "$", "name_field", ")", ";", "$", "search", "=", "array_unique", "(", "array", "(", "$", "name_field", ",", "$", "uid_field", ")", ")", ";", "$", "config", "[", "'search_fields'", "]", "=", "$", "search", ";", "$", "config", "[", "'required_fields'", "]", "=", "array", "(", "$", "uid_field", ")", ";", "// set search filter", "if", "(", "$", "filter", ")", "{", "$", "config", "[", "'filter'", "]", "=", "$", "filter", ";", "}", "// disable vlv", "$", "config", "[", "'vlv'", "]", "=", "false", ";", "// Initialize LDAP connection", "$", "this", "->", "ldap", "=", "new", "rcube_ldap", "(", "$", "config", ",", "$", "this", "->", "rc", "->", "config", "->", "get", "(", "'ldap_debug'", ")", ",", "$", "this", "->", "rc", "->", "config", "->", "mail_domain", "(", "$", "_SESSION", "[", "'imap_host'", "]", ")", ")", ";", "return", "$", "this", "->", "ldap", "->", "ready", ";", "}" ]
Initializes autocomplete LDAP backend
[ "Initializes", "autocomplete", "LDAP", "backend" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/plugins/acl/acl.php#L707-L768
train
i-MSCP/roundcube
roundcubemail/plugins/acl/acl.php
acl.mod_login
protected function mod_login($user) { $login_lc = $this->rc->config->get('login_lc'); if ($login_lc === true || $login_lc == 2) { $user = mb_strtolower($user); } // lowercase domain name else if ($login_lc && strpos($user, '@')) { list($local, $domain) = explode('@', $user); $user = $local . '@' . mb_strtolower($domain); } return $user; }
php
protected function mod_login($user) { $login_lc = $this->rc->config->get('login_lc'); if ($login_lc === true || $login_lc == 2) { $user = mb_strtolower($user); } // lowercase domain name else if ($login_lc && strpos($user, '@')) { list($local, $domain) = explode('@', $user); $user = $local . '@' . mb_strtolower($domain); } return $user; }
[ "protected", "function", "mod_login", "(", "$", "user", ")", "{", "$", "login_lc", "=", "$", "this", "->", "rc", "->", "config", "->", "get", "(", "'login_lc'", ")", ";", "if", "(", "$", "login_lc", "===", "true", "||", "$", "login_lc", "==", "2", ")", "{", "$", "user", "=", "mb_strtolower", "(", "$", "user", ")", ";", "}", "// lowercase domain name", "else", "if", "(", "$", "login_lc", "&&", "strpos", "(", "$", "user", ",", "'@'", ")", ")", "{", "list", "(", "$", "local", ",", "$", "domain", ")", "=", "explode", "(", "'@'", ",", "$", "user", ")", ";", "$", "user", "=", "$", "local", ".", "'@'", ".", "mb_strtolower", "(", "$", "domain", ")", ";", "}", "return", "$", "user", ";", "}" ]
Modify user login according to 'login_lc' setting
[ "Modify", "user", "login", "according", "to", "login_lc", "setting" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/plugins/acl/acl.php#L773-L787
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_message.php
rcube_message.set_safe
public function set_safe($safe = true) { $_SESSION['safe_messages'][$this->folder.':'.$this->uid] = $this->is_safe = $safe; }
php
public function set_safe($safe = true) { $_SESSION['safe_messages'][$this->folder.':'.$this->uid] = $this->is_safe = $safe; }
[ "public", "function", "set_safe", "(", "$", "safe", "=", "true", ")", "{", "$", "_SESSION", "[", "'safe_messages'", "]", "[", "$", "this", "->", "folder", ".", "':'", ".", "$", "this", "->", "uid", "]", "=", "$", "this", "->", "is_safe", "=", "$", "safe", ";", "}" ]
Set is_safe var and session data @param bool $safe enable/disable
[ "Set", "is_safe", "var", "and", "session", "data" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_message.php#L156-L159
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_message.php
rcube_message.get_part_url
public function get_part_url($mime_id, $embed = false) { if ($this->mime_parts[$mime_id]) return $this->opt['get_url'] . '&_part=' . $mime_id . ($embed ? '&_embed=1&_mimeclass=' . $embed : ''); else return false; }
php
public function get_part_url($mime_id, $embed = false) { if ($this->mime_parts[$mime_id]) return $this->opt['get_url'] . '&_part=' . $mime_id . ($embed ? '&_embed=1&_mimeclass=' . $embed : ''); else return false; }
[ "public", "function", "get_part_url", "(", "$", "mime_id", ",", "$", "embed", "=", "false", ")", "{", "if", "(", "$", "this", "->", "mime_parts", "[", "$", "mime_id", "]", ")", "return", "$", "this", "->", "opt", "[", "'get_url'", "]", ".", "'&_part='", ".", "$", "mime_id", ".", "(", "$", "embed", "?", "'&_embed=1&_mimeclass='", ".", "$", "embed", ":", "''", ")", ";", "else", "return", "false", ";", "}" ]
Compose a valid URL for getting a message part @param string $mime_id Part MIME-ID @param mixed $embed Mimetype class for parts to be embedded @return string URL or false if part does not exist
[ "Compose", "a", "valid", "URL", "for", "getting", "a", "message", "part" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_message.php#L168-L174
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_message.php
rcube_message.format_part_body
public static function format_part_body($body, $part, $default_charset = null) { // remove useless characters $body = preg_replace('/[\t\r\0\x0B]+\n/', "\n", $body); // remove NULL characters if any (#1486189) if (strpos($body, "\x00") !== false) { $body = str_replace("\x00", '', $body); } // detect charset... if (!$part->charset || strtoupper($part->charset) == 'US-ASCII') { // try to extract charset information from HTML meta tag (#1488125) if ($part->ctype_secondary == 'html' && preg_match('/<meta[^>]+charset=([a-z0-9-_]+)/i', $body, $m)) { $part->charset = strtoupper($m[1]); } else if ($default_charset) { $part->charset = $default_charset; } else { $rcube = rcube::get_instance(); $part->charset = $rcube->config->get('default_charset', RCUBE_CHARSET); } } // ..convert charset encoding $body = rcube_charset::convert($body, $part->charset); return $body; }
php
public static function format_part_body($body, $part, $default_charset = null) { // remove useless characters $body = preg_replace('/[\t\r\0\x0B]+\n/', "\n", $body); // remove NULL characters if any (#1486189) if (strpos($body, "\x00") !== false) { $body = str_replace("\x00", '', $body); } // detect charset... if (!$part->charset || strtoupper($part->charset) == 'US-ASCII') { // try to extract charset information from HTML meta tag (#1488125) if ($part->ctype_secondary == 'html' && preg_match('/<meta[^>]+charset=([a-z0-9-_]+)/i', $body, $m)) { $part->charset = strtoupper($m[1]); } else if ($default_charset) { $part->charset = $default_charset; } else { $rcube = rcube::get_instance(); $part->charset = $rcube->config->get('default_charset', RCUBE_CHARSET); } } // ..convert charset encoding $body = rcube_charset::convert($body, $part->charset); return $body; }
[ "public", "static", "function", "format_part_body", "(", "$", "body", ",", "$", "part", ",", "$", "default_charset", "=", "null", ")", "{", "// remove useless characters", "$", "body", "=", "preg_replace", "(", "'/[\\t\\r\\0\\x0B]+\\n/'", ",", "\"\\n\"", ",", "$", "body", ")", ";", "// remove NULL characters if any (#1486189)", "if", "(", "strpos", "(", "$", "body", ",", "\"\\x00\"", ")", "!==", "false", ")", "{", "$", "body", "=", "str_replace", "(", "\"\\x00\"", ",", "''", ",", "$", "body", ")", ";", "}", "// detect charset...", "if", "(", "!", "$", "part", "->", "charset", "||", "strtoupper", "(", "$", "part", "->", "charset", ")", "==", "'US-ASCII'", ")", "{", "// try to extract charset information from HTML meta tag (#1488125)", "if", "(", "$", "part", "->", "ctype_secondary", "==", "'html'", "&&", "preg_match", "(", "'/<meta[^>]+charset=([a-z0-9-_]+)/i'", ",", "$", "body", ",", "$", "m", ")", ")", "{", "$", "part", "->", "charset", "=", "strtoupper", "(", "$", "m", "[", "1", "]", ")", ";", "}", "else", "if", "(", "$", "default_charset", ")", "{", "$", "part", "->", "charset", "=", "$", "default_charset", ";", "}", "else", "{", "$", "rcube", "=", "rcube", "::", "get_instance", "(", ")", ";", "$", "part", "->", "charset", "=", "$", "rcube", "->", "config", "->", "get", "(", "'default_charset'", ",", "RCUBE_CHARSET", ")", ";", "}", "}", "// ..convert charset encoding", "$", "body", "=", "rcube_charset", "::", "convert", "(", "$", "body", ",", "$", "part", "->", "charset", ")", ";", "return", "$", "body", ";", "}" ]
Format text message part for display @param string $body Part body @param rcube_message_part $part Part object @param string $default_charset Fallback charset if part charset is not specified @return string Formatted body
[ "Format", "text", "message", "part", "for", "display" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_message.php#L299-L328
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_message.php
rcube_message.first_html_part
public function first_html_part(&$part = null, $enriched = false) { if ($this->has_html_part($enriched, $part)) { $body = $this->get_part_body($part->mime_id, true); if ($part->mimetype == 'text/enriched') { $body = rcube_enriched::to_html($body); } return $body; } }
php
public function first_html_part(&$part = null, $enriched = false) { if ($this->has_html_part($enriched, $part)) { $body = $this->get_part_body($part->mime_id, true); if ($part->mimetype == 'text/enriched') { $body = rcube_enriched::to_html($body); } return $body; } }
[ "public", "function", "first_html_part", "(", "&", "$", "part", "=", "null", ",", "$", "enriched", "=", "false", ")", "{", "if", "(", "$", "this", "->", "has_html_part", "(", "$", "enriched", ",", "$", "part", ")", ")", "{", "$", "body", "=", "$", "this", "->", "get_part_body", "(", "$", "part", "->", "mime_id", ",", "true", ")", ";", "if", "(", "$", "part", "->", "mimetype", "==", "'text/enriched'", ")", "{", "$", "body", "=", "rcube_enriched", "::", "to_html", "(", "$", "body", ")", ";", "}", "return", "$", "body", ";", "}", "}" ]
Return the first HTML part of this message @param rcube_message_part &$part Reference to the part if found @param bool $enriched Enables checking for text/enriched parts too @return string HTML message part content
[ "Return", "the", "first", "HTML", "part", "of", "this", "message" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_message.php#L455-L466
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_message.php
rcube_message.mime_parts
public function mime_parts() { if ($this->context === null) { return $this->mime_parts; } $parts = array(); foreach ($this->mime_parts as $part_id => $part) { if ($this->check_context($part)) { $parts[$part_id] = $part; } } return $parts; }
php
public function mime_parts() { if ($this->context === null) { return $this->mime_parts; } $parts = array(); foreach ($this->mime_parts as $part_id => $part) { if ($this->check_context($part)) { $parts[$part_id] = $part; } } return $parts; }
[ "public", "function", "mime_parts", "(", ")", "{", "if", "(", "$", "this", "->", "context", "===", "null", ")", "{", "return", "$", "this", "->", "mime_parts", ";", "}", "$", "parts", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "mime_parts", "as", "$", "part_id", "=>", "$", "part", ")", "{", "if", "(", "$", "this", "->", "check_context", "(", "$", "part", ")", ")", "{", "$", "parts", "[", "$", "part_id", "]", "=", "$", "part", ";", "}", "}", "return", "$", "parts", ";", "}" ]
Return message parts in current context
[ "Return", "message", "parts", "in", "current", "context" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_message.php#L499-L514
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_message.php
rcube_message.get_mime_numbers
private function get_mime_numbers(&$part) { if (strlen($part->mime_id)) $this->mime_parts[$part->mime_id] = &$part; if (is_array($part->parts)) for ($i=0; $i<count($part->parts); $i++) $this->get_mime_numbers($part->parts[$i]); }
php
private function get_mime_numbers(&$part) { if (strlen($part->mime_id)) $this->mime_parts[$part->mime_id] = &$part; if (is_array($part->parts)) for ($i=0; $i<count($part->parts); $i++) $this->get_mime_numbers($part->parts[$i]); }
[ "private", "function", "get_mime_numbers", "(", "&", "$", "part", ")", "{", "if", "(", "strlen", "(", "$", "part", "->", "mime_id", ")", ")", "$", "this", "->", "mime_parts", "[", "$", "part", "->", "mime_id", "]", "=", "&", "$", "part", ";", "if", "(", "is_array", "(", "$", "part", "->", "parts", ")", ")", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "count", "(", "$", "part", "->", "parts", ")", ";", "$", "i", "++", ")", "$", "this", "->", "get_mime_numbers", "(", "$", "part", "->", "parts", "[", "$", "i", "]", ")", ";", "}" ]
Fill a flat array with references to all parts, indexed by part numbers @param rcube_message_part $part Message body structure
[ "Fill", "a", "flat", "array", "with", "references", "to", "all", "parts", "indexed", "by", "part", "numbers" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_message.php#L928-L936
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_message.php
rcube_message.check_context
private function check_context($part) { return $this->context === null || strpos($part->mime_id, $this->context . '.') === 0; }
php
private function check_context($part) { return $this->context === null || strpos($part->mime_id, $this->context . '.') === 0; }
[ "private", "function", "check_context", "(", "$", "part", ")", "{", "return", "$", "this", "->", "context", "===", "null", "||", "strpos", "(", "$", "part", "->", "mime_id", ",", "$", "this", "->", "context", ".", "'.'", ")", "===", "0", ";", "}" ]
Check if specified part belongs to the current context
[ "Check", "if", "specified", "part", "belongs", "to", "the", "current", "context" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_message.php#L955-L958
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_message.php
rcube_message.uu_decode
function uu_decode(&$part) { // @TODO: messages may be huge, handle body via file $part->body = $this->get_part_body($part->mime_id); $parts = array(); $pid = 0; // FIXME: line length is max.65? $uu_regexp_begin = '/begin [0-7]{3,4} ([^\r\n]+)\r?\n/s'; $uu_regexp_end = '/`\r?\nend((\r?\n)|($))/s'; while (preg_match($uu_regexp_begin, $part->body, $matches, PREG_OFFSET_CAPTURE)) { $startpos = $matches[0][1]; if (!preg_match($uu_regexp_end, $part->body, $m, PREG_OFFSET_CAPTURE, $startpos)) { break; } $endpos = $m[0][1]; $begin_len = strlen($matches[0][0]); $end_len = strlen($m[0][0]); // extract attachment body $filebody = substr($part->body, $startpos + $begin_len, $endpos - $startpos - $begin_len - 1); $filebody = str_replace("\r\n", "\n", $filebody); // remove attachment body from the message body $part->body = substr_replace($part->body, '', $startpos, $endpos + $end_len - $startpos); // mark body as modified so it will not be cached by rcube_imap_cache $part->body_modified = true; // add attachments to the structure $uupart = new rcube_message_part; $uupart->filename = trim($matches[1][0]); $uupart->encoding = 'stream'; $uupart->body = convert_uudecode($filebody); $uupart->size = strlen($uupart->body); $uupart->mime_id = 'uu.' . $part->mime_id . '.' . $pid; $ctype = rcube_mime::file_content_type($uupart->body, $uupart->filename, 'application/octet-stream', true); $uupart->mimetype = $ctype; list($uupart->ctype_primary, $uupart->ctype_secondary) = explode('/', $ctype); $parts[] = $uupart; $pid++; } return $parts; }
php
function uu_decode(&$part) { // @TODO: messages may be huge, handle body via file $part->body = $this->get_part_body($part->mime_id); $parts = array(); $pid = 0; // FIXME: line length is max.65? $uu_regexp_begin = '/begin [0-7]{3,4} ([^\r\n]+)\r?\n/s'; $uu_regexp_end = '/`\r?\nend((\r?\n)|($))/s'; while (preg_match($uu_regexp_begin, $part->body, $matches, PREG_OFFSET_CAPTURE)) { $startpos = $matches[0][1]; if (!preg_match($uu_regexp_end, $part->body, $m, PREG_OFFSET_CAPTURE, $startpos)) { break; } $endpos = $m[0][1]; $begin_len = strlen($matches[0][0]); $end_len = strlen($m[0][0]); // extract attachment body $filebody = substr($part->body, $startpos + $begin_len, $endpos - $startpos - $begin_len - 1); $filebody = str_replace("\r\n", "\n", $filebody); // remove attachment body from the message body $part->body = substr_replace($part->body, '', $startpos, $endpos + $end_len - $startpos); // mark body as modified so it will not be cached by rcube_imap_cache $part->body_modified = true; // add attachments to the structure $uupart = new rcube_message_part; $uupart->filename = trim($matches[1][0]); $uupart->encoding = 'stream'; $uupart->body = convert_uudecode($filebody); $uupart->size = strlen($uupart->body); $uupart->mime_id = 'uu.' . $part->mime_id . '.' . $pid; $ctype = rcube_mime::file_content_type($uupart->body, $uupart->filename, 'application/octet-stream', true); $uupart->mimetype = $ctype; list($uupart->ctype_primary, $uupart->ctype_secondary) = explode('/', $ctype); $parts[] = $uupart; $pid++; } return $parts; }
[ "function", "uu_decode", "(", "&", "$", "part", ")", "{", "// @TODO: messages may be huge, handle body via file", "$", "part", "->", "body", "=", "$", "this", "->", "get_part_body", "(", "$", "part", "->", "mime_id", ")", ";", "$", "parts", "=", "array", "(", ")", ";", "$", "pid", "=", "0", ";", "// FIXME: line length is max.65?", "$", "uu_regexp_begin", "=", "'/begin [0-7]{3,4} ([^\\r\\n]+)\\r?\\n/s'", ";", "$", "uu_regexp_end", "=", "'/`\\r?\\nend((\\r?\\n)|($))/s'", ";", "while", "(", "preg_match", "(", "$", "uu_regexp_begin", ",", "$", "part", "->", "body", ",", "$", "matches", ",", "PREG_OFFSET_CAPTURE", ")", ")", "{", "$", "startpos", "=", "$", "matches", "[", "0", "]", "[", "1", "]", ";", "if", "(", "!", "preg_match", "(", "$", "uu_regexp_end", ",", "$", "part", "->", "body", ",", "$", "m", ",", "PREG_OFFSET_CAPTURE", ",", "$", "startpos", ")", ")", "{", "break", ";", "}", "$", "endpos", "=", "$", "m", "[", "0", "]", "[", "1", "]", ";", "$", "begin_len", "=", "strlen", "(", "$", "matches", "[", "0", "]", "[", "0", "]", ")", ";", "$", "end_len", "=", "strlen", "(", "$", "m", "[", "0", "]", "[", "0", "]", ")", ";", "// extract attachment body", "$", "filebody", "=", "substr", "(", "$", "part", "->", "body", ",", "$", "startpos", "+", "$", "begin_len", ",", "$", "endpos", "-", "$", "startpos", "-", "$", "begin_len", "-", "1", ")", ";", "$", "filebody", "=", "str_replace", "(", "\"\\r\\n\"", ",", "\"\\n\"", ",", "$", "filebody", ")", ";", "// remove attachment body from the message body", "$", "part", "->", "body", "=", "substr_replace", "(", "$", "part", "->", "body", ",", "''", ",", "$", "startpos", ",", "$", "endpos", "+", "$", "end_len", "-", "$", "startpos", ")", ";", "// mark body as modified so it will not be cached by rcube_imap_cache", "$", "part", "->", "body_modified", "=", "true", ";", "// add attachments to the structure", "$", "uupart", "=", "new", "rcube_message_part", ";", "$", "uupart", "->", "filename", "=", "trim", "(", "$", "matches", "[", "1", "]", "[", "0", "]", ")", ";", "$", "uupart", "->", "encoding", "=", "'stream'", ";", "$", "uupart", "->", "body", "=", "convert_uudecode", "(", "$", "filebody", ")", ";", "$", "uupart", "->", "size", "=", "strlen", "(", "$", "uupart", "->", "body", ")", ";", "$", "uupart", "->", "mime_id", "=", "'uu.'", ".", "$", "part", "->", "mime_id", ".", "'.'", ".", "$", "pid", ";", "$", "ctype", "=", "rcube_mime", "::", "file_content_type", "(", "$", "uupart", "->", "body", ",", "$", "uupart", "->", "filename", ",", "'application/octet-stream'", ",", "true", ")", ";", "$", "uupart", "->", "mimetype", "=", "$", "ctype", ";", "list", "(", "$", "uupart", "->", "ctype_primary", ",", "$", "uupart", "->", "ctype_secondary", ")", "=", "explode", "(", "'/'", ",", "$", "ctype", ")", ";", "$", "parts", "[", "]", "=", "$", "uupart", ";", "$", "pid", "++", ";", "}", "return", "$", "parts", ";", "}" ]
Parse message body for UUencoded attachments bodies @param rcube_message_part $part Message part to decode @return array
[ "Parse", "message", "body", "for", "UUencoded", "attachments", "bodies" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_message.php#L1001-L1049
train
netgen/NetgenInformationCollectionBundle
bundle/Form/Captcha/CaptchaService.php
CaptchaService.getConfig
protected function getConfig(Location $location) { $contentTypeConfig = $this->getConfigForContentType( $this->getContentType($location) ); return array_replace($this->config, $contentTypeConfig); }
php
protected function getConfig(Location $location) { $contentTypeConfig = $this->getConfigForContentType( $this->getContentType($location) ); return array_replace($this->config, $contentTypeConfig); }
[ "protected", "function", "getConfig", "(", "Location", "$", "location", ")", "{", "$", "contentTypeConfig", "=", "$", "this", "->", "getConfigForContentType", "(", "$", "this", "->", "getContentType", "(", "$", "location", ")", ")", ";", "return", "array_replace", "(", "$", "this", "->", "config", ",", "$", "contentTypeConfig", ")", ";", "}" ]
Returns filtered config for current Location @param \eZ\Publish\API\Repository\Values\Content\Location $location @return array @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException
[ "Returns", "filtered", "config", "for", "current", "Location" ]
3ed7a2b33b1e80d3a0d9ee607eab495396044b29
https://github.com/netgen/NetgenInformationCollectionBundle/blob/3ed7a2b33b1e80d3a0d9ee607eab495396044b29/bundle/Form/Captcha/CaptchaService.php#L98-L105
train
netgen/NetgenInformationCollectionBundle
bundle/Form/Captcha/CaptchaService.php
CaptchaService.getConfigForContentType
protected function getConfigForContentType(ContentType $contentType) { if ($this->hasConfigForContentType($contentType)) { return $this->config['override_by_type'][$contentType->identifier]; } return []; }
php
protected function getConfigForContentType(ContentType $contentType) { if ($this->hasConfigForContentType($contentType)) { return $this->config['override_by_type'][$contentType->identifier]; } return []; }
[ "protected", "function", "getConfigForContentType", "(", "ContentType", "$", "contentType", ")", "{", "if", "(", "$", "this", "->", "hasConfigForContentType", "(", "$", "contentType", ")", ")", "{", "return", "$", "this", "->", "config", "[", "'override_by_type'", "]", "[", "$", "contentType", "->", "identifier", "]", ";", "}", "return", "[", "]", ";", "}" ]
Returns filtered config for current ContentType @param \eZ\Publish\API\Repository\Values\ContentType\ContentType $contentType @return array
[ "Returns", "filtered", "config", "for", "current", "ContentType" ]
3ed7a2b33b1e80d3a0d9ee607eab495396044b29
https://github.com/netgen/NetgenInformationCollectionBundle/blob/3ed7a2b33b1e80d3a0d9ee607eab495396044b29/bundle/Form/Captcha/CaptchaService.php#L114-L121
train
netgen/NetgenInformationCollectionBundle
bundle/Form/Captcha/CaptchaService.php
CaptchaService.hasConfigForContentType
protected function hasConfigForContentType(ContentType $contentType) { if (!empty($this->config['override_by_type'])) { if (in_array($contentType->identifier, array_keys($this->config['override_by_type']))) { return true; } } return false; }
php
protected function hasConfigForContentType(ContentType $contentType) { if (!empty($this->config['override_by_type'])) { if (in_array($contentType->identifier, array_keys($this->config['override_by_type']))) { return true; } } return false; }
[ "protected", "function", "hasConfigForContentType", "(", "ContentType", "$", "contentType", ")", "{", "if", "(", "!", "empty", "(", "$", "this", "->", "config", "[", "'override_by_type'", "]", ")", ")", "{", "if", "(", "in_array", "(", "$", "contentType", "->", "identifier", ",", "array_keys", "(", "$", "this", "->", "config", "[", "'override_by_type'", "]", ")", ")", ")", "{", "return", "true", ";", "}", "}", "return", "false", ";", "}" ]
Checks if override exist for given ContentType @param \eZ\Publish\API\Repository\Values\ContentType\ContentType $contentType @return bool
[ "Checks", "if", "override", "exist", "for", "given", "ContentType" ]
3ed7a2b33b1e80d3a0d9ee607eab495396044b29
https://github.com/netgen/NetgenInformationCollectionBundle/blob/3ed7a2b33b1e80d3a0d9ee607eab495396044b29/bundle/Form/Captcha/CaptchaService.php#L130-L139
train
i-MSCP/roundcube
roundcubemail/plugins/enigma/lib/enigma_engine.php
enigma_engine.load_pgp_driver
function load_pgp_driver() { if ($this->pgp_driver) { return; } $driver = 'enigma_driver_' . $this->rc->config->get('enigma_pgp_driver', 'gnupg'); $username = $this->rc->user->get_username(); // Load driver $this->pgp_driver = new $driver($username); if (!$this->pgp_driver) { rcube::raise_error(array( 'code' => 600, 'type' => 'php', 'file' => __FILE__, 'line' => __LINE__, 'message' => "Enigma plugin: Unable to load PGP driver: $driver" ), true, true); } // Initialise driver $result = $this->pgp_driver->init(); if ($result instanceof enigma_error) { self::raise_error($result, __LINE__, true); } }
php
function load_pgp_driver() { if ($this->pgp_driver) { return; } $driver = 'enigma_driver_' . $this->rc->config->get('enigma_pgp_driver', 'gnupg'); $username = $this->rc->user->get_username(); // Load driver $this->pgp_driver = new $driver($username); if (!$this->pgp_driver) { rcube::raise_error(array( 'code' => 600, 'type' => 'php', 'file' => __FILE__, 'line' => __LINE__, 'message' => "Enigma plugin: Unable to load PGP driver: $driver" ), true, true); } // Initialise driver $result = $this->pgp_driver->init(); if ($result instanceof enigma_error) { self::raise_error($result, __LINE__, true); } }
[ "function", "load_pgp_driver", "(", ")", "{", "if", "(", "$", "this", "->", "pgp_driver", ")", "{", "return", ";", "}", "$", "driver", "=", "'enigma_driver_'", ".", "$", "this", "->", "rc", "->", "config", "->", "get", "(", "'enigma_pgp_driver'", ",", "'gnupg'", ")", ";", "$", "username", "=", "$", "this", "->", "rc", "->", "user", "->", "get_username", "(", ")", ";", "// Load driver", "$", "this", "->", "pgp_driver", "=", "new", "$", "driver", "(", "$", "username", ")", ";", "if", "(", "!", "$", "this", "->", "pgp_driver", ")", "{", "rcube", "::", "raise_error", "(", "array", "(", "'code'", "=>", "600", ",", "'type'", "=>", "'php'", ",", "'file'", "=>", "__FILE__", ",", "'line'", "=>", "__LINE__", ",", "'message'", "=>", "\"Enigma plugin: Unable to load PGP driver: $driver\"", ")", ",", "true", ",", "true", ")", ";", "}", "// Initialise driver", "$", "result", "=", "$", "this", "->", "pgp_driver", "->", "init", "(", ")", ";", "if", "(", "$", "result", "instanceof", "enigma_error", ")", "{", "self", "::", "raise_error", "(", "$", "result", ",", "__LINE__", ",", "true", ")", ";", "}", "}" ]
PGP driver initialization.
[ "PGP", "driver", "initialization", "." ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/plugins/enigma/lib/enigma_engine.php#L68-L94
train
i-MSCP/roundcube
roundcubemail/plugins/enigma/lib/enigma_engine.php
enigma_engine.sign_message
function sign_message(&$message, $mode = null) { $mime = new enigma_mime_message($message, enigma_mime_message::PGP_SIGNED); $from = $mime->getFromAddress(); // find private key $key = $this->find_key($from, true); if (empty($key)) { return new enigma_error(enigma_error::KEYNOTFOUND); } // check if we have password for this key $passwords = $this->get_passwords(); $pass = $passwords[$key->id]; if ($pass === null) { // ask for password $error = array('missing' => array($key->id => $key->name)); return new enigma_error(enigma_error::BADPASS, '', $error); } $key->password = $pass; // select mode switch ($mode) { case self::SIGN_MODE_BODY: $pgp_mode = Crypt_GPG::SIGN_MODE_CLEAR; break; case self::SIGN_MODE_MIME: $pgp_mode = Crypt_GPG::SIGN_MODE_DETACHED; break; default: if ($mime->isMultipart()) { $pgp_mode = Crypt_GPG::SIGN_MODE_DETACHED; } else { $pgp_mode = Crypt_GPG::SIGN_MODE_CLEAR; } } // get message body if ($pgp_mode == Crypt_GPG::SIGN_MODE_CLEAR) { // in this mode we'll replace text part // with the one containing signature $body = $message->getTXTBody(); $text_charset = $message->getParam('text_charset'); $line_length = $this->rc->config->get('line_length', 72); // We can't use format=flowed for signed messages if (strpos($text_charset, 'format=flowed')) { list($charset, $params) = explode(';', $text_charset); $body = rcube_mime::unfold_flowed($body); $body = rcube_mime::wordwrap($body, $line_length, "\r\n", false, $charset); $text_charset = str_replace(";\r\n format=flowed", '', $text_charset); } } else { // here we'll build PGP/MIME message $body = $mime->getOrigBody(); } // sign the body $result = $this->pgp_sign($body, $key, $pgp_mode); if ($result !== true) { if ($result->getCode() == enigma_error::BADPASS) { // ask for password $error = array('bad' => array($key->id => $key->name)); return new enigma_error(enigma_error::BADPASS, '', $error); } return $result; } // replace message body if ($pgp_mode == Crypt_GPG::SIGN_MODE_CLEAR) { $message->setTXTBody($body); $message->setParam('text_charset', $text_charset); } else { $mime->addPGPSignature($body, $this->pgp_driver->signature_algorithm()); $message = $mime; } }
php
function sign_message(&$message, $mode = null) { $mime = new enigma_mime_message($message, enigma_mime_message::PGP_SIGNED); $from = $mime->getFromAddress(); // find private key $key = $this->find_key($from, true); if (empty($key)) { return new enigma_error(enigma_error::KEYNOTFOUND); } // check if we have password for this key $passwords = $this->get_passwords(); $pass = $passwords[$key->id]; if ($pass === null) { // ask for password $error = array('missing' => array($key->id => $key->name)); return new enigma_error(enigma_error::BADPASS, '', $error); } $key->password = $pass; // select mode switch ($mode) { case self::SIGN_MODE_BODY: $pgp_mode = Crypt_GPG::SIGN_MODE_CLEAR; break; case self::SIGN_MODE_MIME: $pgp_mode = Crypt_GPG::SIGN_MODE_DETACHED; break; default: if ($mime->isMultipart()) { $pgp_mode = Crypt_GPG::SIGN_MODE_DETACHED; } else { $pgp_mode = Crypt_GPG::SIGN_MODE_CLEAR; } } // get message body if ($pgp_mode == Crypt_GPG::SIGN_MODE_CLEAR) { // in this mode we'll replace text part // with the one containing signature $body = $message->getTXTBody(); $text_charset = $message->getParam('text_charset'); $line_length = $this->rc->config->get('line_length', 72); // We can't use format=flowed for signed messages if (strpos($text_charset, 'format=flowed')) { list($charset, $params) = explode(';', $text_charset); $body = rcube_mime::unfold_flowed($body); $body = rcube_mime::wordwrap($body, $line_length, "\r\n", false, $charset); $text_charset = str_replace(";\r\n format=flowed", '', $text_charset); } } else { // here we'll build PGP/MIME message $body = $mime->getOrigBody(); } // sign the body $result = $this->pgp_sign($body, $key, $pgp_mode); if ($result !== true) { if ($result->getCode() == enigma_error::BADPASS) { // ask for password $error = array('bad' => array($key->id => $key->name)); return new enigma_error(enigma_error::BADPASS, '', $error); } return $result; } // replace message body if ($pgp_mode == Crypt_GPG::SIGN_MODE_CLEAR) { $message->setTXTBody($body); $message->setParam('text_charset', $text_charset); } else { $mime->addPGPSignature($body, $this->pgp_driver->signature_algorithm()); $message = $mime; } }
[ "function", "sign_message", "(", "&", "$", "message", ",", "$", "mode", "=", "null", ")", "{", "$", "mime", "=", "new", "enigma_mime_message", "(", "$", "message", ",", "enigma_mime_message", "::", "PGP_SIGNED", ")", ";", "$", "from", "=", "$", "mime", "->", "getFromAddress", "(", ")", ";", "// find private key", "$", "key", "=", "$", "this", "->", "find_key", "(", "$", "from", ",", "true", ")", ";", "if", "(", "empty", "(", "$", "key", ")", ")", "{", "return", "new", "enigma_error", "(", "enigma_error", "::", "KEYNOTFOUND", ")", ";", "}", "// check if we have password for this key", "$", "passwords", "=", "$", "this", "->", "get_passwords", "(", ")", ";", "$", "pass", "=", "$", "passwords", "[", "$", "key", "->", "id", "]", ";", "if", "(", "$", "pass", "===", "null", ")", "{", "// ask for password", "$", "error", "=", "array", "(", "'missing'", "=>", "array", "(", "$", "key", "->", "id", "=>", "$", "key", "->", "name", ")", ")", ";", "return", "new", "enigma_error", "(", "enigma_error", "::", "BADPASS", ",", "''", ",", "$", "error", ")", ";", "}", "$", "key", "->", "password", "=", "$", "pass", ";", "// select mode", "switch", "(", "$", "mode", ")", "{", "case", "self", "::", "SIGN_MODE_BODY", ":", "$", "pgp_mode", "=", "Crypt_GPG", "::", "SIGN_MODE_CLEAR", ";", "break", ";", "case", "self", "::", "SIGN_MODE_MIME", ":", "$", "pgp_mode", "=", "Crypt_GPG", "::", "SIGN_MODE_DETACHED", ";", "break", ";", "default", ":", "if", "(", "$", "mime", "->", "isMultipart", "(", ")", ")", "{", "$", "pgp_mode", "=", "Crypt_GPG", "::", "SIGN_MODE_DETACHED", ";", "}", "else", "{", "$", "pgp_mode", "=", "Crypt_GPG", "::", "SIGN_MODE_CLEAR", ";", "}", "}", "// get message body", "if", "(", "$", "pgp_mode", "==", "Crypt_GPG", "::", "SIGN_MODE_CLEAR", ")", "{", "// in this mode we'll replace text part", "// with the one containing signature", "$", "body", "=", "$", "message", "->", "getTXTBody", "(", ")", ";", "$", "text_charset", "=", "$", "message", "->", "getParam", "(", "'text_charset'", ")", ";", "$", "line_length", "=", "$", "this", "->", "rc", "->", "config", "->", "get", "(", "'line_length'", ",", "72", ")", ";", "// We can't use format=flowed for signed messages", "if", "(", "strpos", "(", "$", "text_charset", ",", "'format=flowed'", ")", ")", "{", "list", "(", "$", "charset", ",", "$", "params", ")", "=", "explode", "(", "';'", ",", "$", "text_charset", ")", ";", "$", "body", "=", "rcube_mime", "::", "unfold_flowed", "(", "$", "body", ")", ";", "$", "body", "=", "rcube_mime", "::", "wordwrap", "(", "$", "body", ",", "$", "line_length", ",", "\"\\r\\n\"", ",", "false", ",", "$", "charset", ")", ";", "$", "text_charset", "=", "str_replace", "(", "\";\\r\\n format=flowed\"", ",", "''", ",", "$", "text_charset", ")", ";", "}", "}", "else", "{", "// here we'll build PGP/MIME message", "$", "body", "=", "$", "mime", "->", "getOrigBody", "(", ")", ";", "}", "// sign the body", "$", "result", "=", "$", "this", "->", "pgp_sign", "(", "$", "body", ",", "$", "key", ",", "$", "pgp_mode", ")", ";", "if", "(", "$", "result", "!==", "true", ")", "{", "if", "(", "$", "result", "->", "getCode", "(", ")", "==", "enigma_error", "::", "BADPASS", ")", "{", "// ask for password", "$", "error", "=", "array", "(", "'bad'", "=>", "array", "(", "$", "key", "->", "id", "=>", "$", "key", "->", "name", ")", ")", ";", "return", "new", "enigma_error", "(", "enigma_error", "::", "BADPASS", ",", "''", ",", "$", "error", ")", ";", "}", "return", "$", "result", ";", "}", "// replace message body", "if", "(", "$", "pgp_mode", "==", "Crypt_GPG", "::", "SIGN_MODE_CLEAR", ")", "{", "$", "message", "->", "setTXTBody", "(", "$", "body", ")", ";", "$", "message", "->", "setParam", "(", "'text_charset'", ",", "$", "text_charset", ")", ";", "}", "else", "{", "$", "mime", "->", "addPGPSignature", "(", "$", "body", ",", "$", "this", "->", "pgp_driver", "->", "signature_algorithm", "(", ")", ")", ";", "$", "message", "=", "$", "mime", ";", "}", "}" ]
Handler for message signing @param Mail_mime Original message @param int Encryption mode @return enigma_error On error returns error object
[ "Handler", "for", "message", "signing" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/plugins/enigma/lib/enigma_engine.php#L135-L223
train
i-MSCP/roundcube
roundcubemail/plugins/enigma/lib/enigma_engine.php
enigma_engine.attach_public_key
function attach_public_key(&$message) { $headers = $message->headers(); $from = rcube_mime::decode_address_list($headers['From'], 1, false, null, true); $from = $from[1]; // find my key if ($from && ($key = $this->find_key($from, true))) { $pubkey_armor = $this->export_key($key->id); if (!$pubkey_armor instanceof enigma_error) { $pubkey_name = '0x' . enigma_key::format_id($key->id) . '.asc'; $message->addAttachment($pubkey_armor, 'application/pgp-keys', $pubkey_name, false, '7bit'); return true; } } return false; }
php
function attach_public_key(&$message) { $headers = $message->headers(); $from = rcube_mime::decode_address_list($headers['From'], 1, false, null, true); $from = $from[1]; // find my key if ($from && ($key = $this->find_key($from, true))) { $pubkey_armor = $this->export_key($key->id); if (!$pubkey_armor instanceof enigma_error) { $pubkey_name = '0x' . enigma_key::format_id($key->id) . '.asc'; $message->addAttachment($pubkey_armor, 'application/pgp-keys', $pubkey_name, false, '7bit'); return true; } } return false; }
[ "function", "attach_public_key", "(", "&", "$", "message", ")", "{", "$", "headers", "=", "$", "message", "->", "headers", "(", ")", ";", "$", "from", "=", "rcube_mime", "::", "decode_address_list", "(", "$", "headers", "[", "'From'", "]", ",", "1", ",", "false", ",", "null", ",", "true", ")", ";", "$", "from", "=", "$", "from", "[", "1", "]", ";", "// find my key", "if", "(", "$", "from", "&&", "(", "$", "key", "=", "$", "this", "->", "find_key", "(", "$", "from", ",", "true", ")", ")", ")", "{", "$", "pubkey_armor", "=", "$", "this", "->", "export_key", "(", "$", "key", "->", "id", ")", ";", "if", "(", "!", "$", "pubkey_armor", "instanceof", "enigma_error", ")", "{", "$", "pubkey_name", "=", "'0x'", ".", "enigma_key", "::", "format_id", "(", "$", "key", "->", "id", ")", ".", "'.asc'", ";", "$", "message", "->", "addAttachment", "(", "$", "pubkey_armor", ",", "'application/pgp-keys'", ",", "$", "pubkey_name", ",", "false", ",", "'7bit'", ")", ";", "return", "true", ";", "}", "}", "return", "false", ";", "}" ]
Handler for attaching public key to a message @param Mail_mime Original message @return bool True on success, False on failure
[ "Handler", "for", "attaching", "public", "key", "to", "a", "message" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/plugins/enigma/lib/enigma_engine.php#L345-L363
train
i-MSCP/roundcube
roundcubemail/plugins/enigma/lib/enigma_engine.php
enigma_engine.part_structure
function part_structure($p, $body = null) { if ($p['mimetype'] == 'text/plain' || $p['mimetype'] == 'application/pgp') { $this->parse_plain($p, $body); } else if ($p['mimetype'] == 'multipart/signed') { $this->parse_signed($p, $body); } else if ($p['mimetype'] == 'multipart/encrypted') { $this->parse_encrypted($p); } else if ($p['mimetype'] == 'application/pkcs7-mime') { $this->parse_encrypted($p); } return $p; }
php
function part_structure($p, $body = null) { if ($p['mimetype'] == 'text/plain' || $p['mimetype'] == 'application/pgp') { $this->parse_plain($p, $body); } else if ($p['mimetype'] == 'multipart/signed') { $this->parse_signed($p, $body); } else if ($p['mimetype'] == 'multipart/encrypted') { $this->parse_encrypted($p); } else if ($p['mimetype'] == 'application/pkcs7-mime') { $this->parse_encrypted($p); } return $p; }
[ "function", "part_structure", "(", "$", "p", ",", "$", "body", "=", "null", ")", "{", "if", "(", "$", "p", "[", "'mimetype'", "]", "==", "'text/plain'", "||", "$", "p", "[", "'mimetype'", "]", "==", "'application/pgp'", ")", "{", "$", "this", "->", "parse_plain", "(", "$", "p", ",", "$", "body", ")", ";", "}", "else", "if", "(", "$", "p", "[", "'mimetype'", "]", "==", "'multipart/signed'", ")", "{", "$", "this", "->", "parse_signed", "(", "$", "p", ",", "$", "body", ")", ";", "}", "else", "if", "(", "$", "p", "[", "'mimetype'", "]", "==", "'multipart/encrypted'", ")", "{", "$", "this", "->", "parse_encrypted", "(", "$", "p", ")", ";", "}", "else", "if", "(", "$", "p", "[", "'mimetype'", "]", "==", "'application/pkcs7-mime'", ")", "{", "$", "this", "->", "parse_encrypted", "(", "$", "p", ")", ";", "}", "return", "$", "p", ";", "}" ]
Handler for message_part_structure hook. Called for every part of the message. @param array Original parameters @param string Part body (will be set if used internally) @return array Modified parameters
[ "Handler", "for", "message_part_structure", "hook", ".", "Called", "for", "every", "part", "of", "the", "message", "." ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/plugins/enigma/lib/enigma_engine.php#L374-L390
train
i-MSCP/roundcube
roundcubemail/plugins/enigma/lib/enigma_engine.php
enigma_engine.part_body
function part_body($p) { // encrypted attachment, see parse_plain_encrypted() if ($p['part']->need_decryption && $p['part']->body === null) { $this->load_pgp_driver(); $storage = $this->rc->get_storage(); $body = $storage->get_message_part($p['object']->uid, $p['part']->mime_id, $p['part'], null, null, true, 0, false); $result = $this->pgp_decrypt($body); // @TODO: what to do on error? if ($result === true) { $p['part']->body = $body; $p['part']->size = strlen($body); $p['part']->body_modified = true; } } return $p; }
php
function part_body($p) { // encrypted attachment, see parse_plain_encrypted() if ($p['part']->need_decryption && $p['part']->body === null) { $this->load_pgp_driver(); $storage = $this->rc->get_storage(); $body = $storage->get_message_part($p['object']->uid, $p['part']->mime_id, $p['part'], null, null, true, 0, false); $result = $this->pgp_decrypt($body); // @TODO: what to do on error? if ($result === true) { $p['part']->body = $body; $p['part']->size = strlen($body); $p['part']->body_modified = true; } } return $p; }
[ "function", "part_body", "(", "$", "p", ")", "{", "// encrypted attachment, see parse_plain_encrypted()", "if", "(", "$", "p", "[", "'part'", "]", "->", "need_decryption", "&&", "$", "p", "[", "'part'", "]", "->", "body", "===", "null", ")", "{", "$", "this", "->", "load_pgp_driver", "(", ")", ";", "$", "storage", "=", "$", "this", "->", "rc", "->", "get_storage", "(", ")", ";", "$", "body", "=", "$", "storage", "->", "get_message_part", "(", "$", "p", "[", "'object'", "]", "->", "uid", ",", "$", "p", "[", "'part'", "]", "->", "mime_id", ",", "$", "p", "[", "'part'", "]", ",", "null", ",", "null", ",", "true", ",", "0", ",", "false", ")", ";", "$", "result", "=", "$", "this", "->", "pgp_decrypt", "(", "$", "body", ")", ";", "// @TODO: what to do on error?", "if", "(", "$", "result", "===", "true", ")", "{", "$", "p", "[", "'part'", "]", "->", "body", "=", "$", "body", ";", "$", "p", "[", "'part'", "]", "->", "size", "=", "strlen", "(", "$", "body", ")", ";", "$", "p", "[", "'part'", "]", "->", "body_modified", "=", "true", ";", "}", "}", "return", "$", "p", ";", "}" ]
Handler for message_part_body hook. @param array Original parameters @return array Modified parameters
[ "Handler", "for", "message_part_body", "hook", "." ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/plugins/enigma/lib/enigma_engine.php#L399-L418
train
i-MSCP/roundcube
roundcubemail/plugins/enigma/lib/enigma_engine.php
enigma_engine.parse_plain_signed
private function parse_plain_signed(&$p, $body, $prefix = '') { if (!$this->rc->config->get('enigma_signatures', true)) { return; } $this->load_pgp_driver(); $part = $p['structure']; // Verify signature if ($this->rc->action == 'show' || $this->rc->action == 'preview' || $this->rc->action == 'print') { $sig = $this->pgp_verify($body); } // In this way we can use fgets on string as on file handle // Don't use php://temp for security (body may come from an encrypted part) $fd = fopen('php://memory', 'r+'); if (!$fd) { return; } fwrite($fd, $body); rewind($fd); $body = $part->body = null; $part->body_modified = true; // Extract body (and signature?) while (($line = fgets($fd, 1024)) !== false) { if ($part->body === null) $part->body = ''; else if (preg_match('/^-----BEGIN PGP SIGNATURE-----/', $line)) break; else $part->body .= $line; } fclose($fd); // Remove "Hash" Armor Headers $part->body = preg_replace('/^.*\r*\n\r*\n/', '', $part->body); // de-Dash-Escape (RFC2440) $part->body = preg_replace('/(^|\n)- -/', '\\1-', $part->body); if ($prefix) { $part->body = $prefix . $part->body; } // Store signature data for display if (!empty($sig)) { $sig->partial = !empty($prefix); $this->signatures[$part->mime_id] = $sig; } }
php
private function parse_plain_signed(&$p, $body, $prefix = '') { if (!$this->rc->config->get('enigma_signatures', true)) { return; } $this->load_pgp_driver(); $part = $p['structure']; // Verify signature if ($this->rc->action == 'show' || $this->rc->action == 'preview' || $this->rc->action == 'print') { $sig = $this->pgp_verify($body); } // In this way we can use fgets on string as on file handle // Don't use php://temp for security (body may come from an encrypted part) $fd = fopen('php://memory', 'r+'); if (!$fd) { return; } fwrite($fd, $body); rewind($fd); $body = $part->body = null; $part->body_modified = true; // Extract body (and signature?) while (($line = fgets($fd, 1024)) !== false) { if ($part->body === null) $part->body = ''; else if (preg_match('/^-----BEGIN PGP SIGNATURE-----/', $line)) break; else $part->body .= $line; } fclose($fd); // Remove "Hash" Armor Headers $part->body = preg_replace('/^.*\r*\n\r*\n/', '', $part->body); // de-Dash-Escape (RFC2440) $part->body = preg_replace('/(^|\n)- -/', '\\1-', $part->body); if ($prefix) { $part->body = $prefix . $part->body; } // Store signature data for display if (!empty($sig)) { $sig->partial = !empty($prefix); $this->signatures[$part->mime_id] = $sig; } }
[ "private", "function", "parse_plain_signed", "(", "&", "$", "p", ",", "$", "body", ",", "$", "prefix", "=", "''", ")", "{", "if", "(", "!", "$", "this", "->", "rc", "->", "config", "->", "get", "(", "'enigma_signatures'", ",", "true", ")", ")", "{", "return", ";", "}", "$", "this", "->", "load_pgp_driver", "(", ")", ";", "$", "part", "=", "$", "p", "[", "'structure'", "]", ";", "// Verify signature", "if", "(", "$", "this", "->", "rc", "->", "action", "==", "'show'", "||", "$", "this", "->", "rc", "->", "action", "==", "'preview'", "||", "$", "this", "->", "rc", "->", "action", "==", "'print'", ")", "{", "$", "sig", "=", "$", "this", "->", "pgp_verify", "(", "$", "body", ")", ";", "}", "// In this way we can use fgets on string as on file handle", "// Don't use php://temp for security (body may come from an encrypted part)", "$", "fd", "=", "fopen", "(", "'php://memory'", ",", "'r+'", ")", ";", "if", "(", "!", "$", "fd", ")", "{", "return", ";", "}", "fwrite", "(", "$", "fd", ",", "$", "body", ")", ";", "rewind", "(", "$", "fd", ")", ";", "$", "body", "=", "$", "part", "->", "body", "=", "null", ";", "$", "part", "->", "body_modified", "=", "true", ";", "// Extract body (and signature?)", "while", "(", "(", "$", "line", "=", "fgets", "(", "$", "fd", ",", "1024", ")", ")", "!==", "false", ")", "{", "if", "(", "$", "part", "->", "body", "===", "null", ")", "$", "part", "->", "body", "=", "''", ";", "else", "if", "(", "preg_match", "(", "'/^-----BEGIN PGP SIGNATURE-----/'", ",", "$", "line", ")", ")", "break", ";", "else", "$", "part", "->", "body", ".=", "$", "line", ";", "}", "fclose", "(", "$", "fd", ")", ";", "// Remove \"Hash\" Armor Headers", "$", "part", "->", "body", "=", "preg_replace", "(", "'/^.*\\r*\\n\\r*\\n/'", ",", "''", ",", "$", "part", "->", "body", ")", ";", "// de-Dash-Escape (RFC2440)", "$", "part", "->", "body", "=", "preg_replace", "(", "'/(^|\\n)- -/'", ",", "'\\\\1-'", ",", "$", "part", "->", "body", ")", ";", "if", "(", "$", "prefix", ")", "{", "$", "part", "->", "body", "=", "$", "prefix", ".", "$", "part", "->", "body", ";", "}", "// Store signature data for display", "if", "(", "!", "empty", "(", "$", "sig", ")", ")", "{", "$", "sig", "->", "partial", "=", "!", "empty", "(", "$", "prefix", ")", ";", "$", "this", "->", "signatures", "[", "$", "part", "->", "mime_id", "]", "=", "$", "sig", ";", "}", "}" ]
Handler for plain signed message. Excludes message and signature bodies and verifies signature. @param array Reference to hook's parameters @param string Message (part) body @param string Body prefix (additional text before the encrypted block)
[ "Handler", "for", "plain", "signed", "message", ".", "Excludes", "message", "and", "signature", "bodies", "and", "verifies", "signature", "." ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/plugins/enigma/lib/enigma_engine.php#L568-L621
train
i-MSCP/roundcube
roundcubemail/plugins/enigma/lib/enigma_engine.php
enigma_engine.parse_plain_encrypted
private function parse_plain_encrypted(&$p, $body, $prefix = '') { if (!$this->rc->config->get('enigma_decryption', true)) { return; } $this->load_pgp_driver(); $part = $p['structure']; // Decrypt $result = $this->pgp_decrypt($body, $signature); // Store decryption status $this->decryptions[$part->mime_id] = $result; // Store signature data for display if ($signature) { $this->signatures[$part->mime_id] = $signature; } // find parent part ID if (strpos($part->mime_id, '.')) { $items = explode('.', $part->mime_id); array_pop($items); $parent = implode('.', $items); } else { $parent = 0; } // Parse decrypted message if ($result === true) { $part->body = $prefix . $body; $part->body_modified = true; // it maybe PGP signed inside, verify signature $this->parse_plain($p, $body); // Remember it was decrypted $this->encrypted_parts[] = $part->mime_id; // Inform the user that only a part of the body was encrypted if ($prefix) { $this->decryptions[$part->mime_id] = self::ENCRYPTED_PARTIALLY; } // Encrypted plain message may contain encrypted attachments // in such case attachments have .pgp extension and type application/octet-stream. // This is what happens when you select "Encrypt each attachment separately // and send the message using inline PGP" in Thunderbird's Enigmail. if ($p['object']->mime_parts[$parent]) { foreach ((array)$p['object']->mime_parts[$parent]->parts as $p) { if ($p->disposition == 'attachment' && $p->mimetype == 'application/octet-stream' && preg_match('/^(.*)\.pgp$/i', $p->filename, $m) ) { // modify filename $p->filename = $m[1]; // flag the part, it will be decrypted when needed $p->need_decryption = true; // disable caching $p->body_modified = true; } } } } // decryption failed, but the message may have already // been cached with the modified parts (see above), // let's bring the original state back else if ($p['object']->mime_parts[$parent]) { foreach ((array)$p['object']->mime_parts[$parent]->parts as $p) { if ($p->need_decryption && !preg_match('/^(.*)\.pgp$/i', $p->filename, $m)) { // modify filename $p->filename .= '.pgp'; // flag the part, it will be decrypted when needed unset($p->need_decryption); } } } }
php
private function parse_plain_encrypted(&$p, $body, $prefix = '') { if (!$this->rc->config->get('enigma_decryption', true)) { return; } $this->load_pgp_driver(); $part = $p['structure']; // Decrypt $result = $this->pgp_decrypt($body, $signature); // Store decryption status $this->decryptions[$part->mime_id] = $result; // Store signature data for display if ($signature) { $this->signatures[$part->mime_id] = $signature; } // find parent part ID if (strpos($part->mime_id, '.')) { $items = explode('.', $part->mime_id); array_pop($items); $parent = implode('.', $items); } else { $parent = 0; } // Parse decrypted message if ($result === true) { $part->body = $prefix . $body; $part->body_modified = true; // it maybe PGP signed inside, verify signature $this->parse_plain($p, $body); // Remember it was decrypted $this->encrypted_parts[] = $part->mime_id; // Inform the user that only a part of the body was encrypted if ($prefix) { $this->decryptions[$part->mime_id] = self::ENCRYPTED_PARTIALLY; } // Encrypted plain message may contain encrypted attachments // in such case attachments have .pgp extension and type application/octet-stream. // This is what happens when you select "Encrypt each attachment separately // and send the message using inline PGP" in Thunderbird's Enigmail. if ($p['object']->mime_parts[$parent]) { foreach ((array)$p['object']->mime_parts[$parent]->parts as $p) { if ($p->disposition == 'attachment' && $p->mimetype == 'application/octet-stream' && preg_match('/^(.*)\.pgp$/i', $p->filename, $m) ) { // modify filename $p->filename = $m[1]; // flag the part, it will be decrypted when needed $p->need_decryption = true; // disable caching $p->body_modified = true; } } } } // decryption failed, but the message may have already // been cached with the modified parts (see above), // let's bring the original state back else if ($p['object']->mime_parts[$parent]) { foreach ((array)$p['object']->mime_parts[$parent]->parts as $p) { if ($p->need_decryption && !preg_match('/^(.*)\.pgp$/i', $p->filename, $m)) { // modify filename $p->filename .= '.pgp'; // flag the part, it will be decrypted when needed unset($p->need_decryption); } } } }
[ "private", "function", "parse_plain_encrypted", "(", "&", "$", "p", ",", "$", "body", ",", "$", "prefix", "=", "''", ")", "{", "if", "(", "!", "$", "this", "->", "rc", "->", "config", "->", "get", "(", "'enigma_decryption'", ",", "true", ")", ")", "{", "return", ";", "}", "$", "this", "->", "load_pgp_driver", "(", ")", ";", "$", "part", "=", "$", "p", "[", "'structure'", "]", ";", "// Decrypt", "$", "result", "=", "$", "this", "->", "pgp_decrypt", "(", "$", "body", ",", "$", "signature", ")", ";", "// Store decryption status", "$", "this", "->", "decryptions", "[", "$", "part", "->", "mime_id", "]", "=", "$", "result", ";", "// Store signature data for display", "if", "(", "$", "signature", ")", "{", "$", "this", "->", "signatures", "[", "$", "part", "->", "mime_id", "]", "=", "$", "signature", ";", "}", "// find parent part ID", "if", "(", "strpos", "(", "$", "part", "->", "mime_id", ",", "'.'", ")", ")", "{", "$", "items", "=", "explode", "(", "'.'", ",", "$", "part", "->", "mime_id", ")", ";", "array_pop", "(", "$", "items", ")", ";", "$", "parent", "=", "implode", "(", "'.'", ",", "$", "items", ")", ";", "}", "else", "{", "$", "parent", "=", "0", ";", "}", "// Parse decrypted message", "if", "(", "$", "result", "===", "true", ")", "{", "$", "part", "->", "body", "=", "$", "prefix", ".", "$", "body", ";", "$", "part", "->", "body_modified", "=", "true", ";", "// it maybe PGP signed inside, verify signature", "$", "this", "->", "parse_plain", "(", "$", "p", ",", "$", "body", ")", ";", "// Remember it was decrypted", "$", "this", "->", "encrypted_parts", "[", "]", "=", "$", "part", "->", "mime_id", ";", "// Inform the user that only a part of the body was encrypted", "if", "(", "$", "prefix", ")", "{", "$", "this", "->", "decryptions", "[", "$", "part", "->", "mime_id", "]", "=", "self", "::", "ENCRYPTED_PARTIALLY", ";", "}", "// Encrypted plain message may contain encrypted attachments", "// in such case attachments have .pgp extension and type application/octet-stream.", "// This is what happens when you select \"Encrypt each attachment separately", "// and send the message using inline PGP\" in Thunderbird's Enigmail.", "if", "(", "$", "p", "[", "'object'", "]", "->", "mime_parts", "[", "$", "parent", "]", ")", "{", "foreach", "(", "(", "array", ")", "$", "p", "[", "'object'", "]", "->", "mime_parts", "[", "$", "parent", "]", "->", "parts", "as", "$", "p", ")", "{", "if", "(", "$", "p", "->", "disposition", "==", "'attachment'", "&&", "$", "p", "->", "mimetype", "==", "'application/octet-stream'", "&&", "preg_match", "(", "'/^(.*)\\.pgp$/i'", ",", "$", "p", "->", "filename", ",", "$", "m", ")", ")", "{", "// modify filename", "$", "p", "->", "filename", "=", "$", "m", "[", "1", "]", ";", "// flag the part, it will be decrypted when needed", "$", "p", "->", "need_decryption", "=", "true", ";", "// disable caching", "$", "p", "->", "body_modified", "=", "true", ";", "}", "}", "}", "}", "// decryption failed, but the message may have already", "// been cached with the modified parts (see above),", "// let's bring the original state back", "else", "if", "(", "$", "p", "[", "'object'", "]", "->", "mime_parts", "[", "$", "parent", "]", ")", "{", "foreach", "(", "(", "array", ")", "$", "p", "[", "'object'", "]", "->", "mime_parts", "[", "$", "parent", "]", "->", "parts", "as", "$", "p", ")", "{", "if", "(", "$", "p", "->", "need_decryption", "&&", "!", "preg_match", "(", "'/^(.*)\\.pgp$/i'", ",", "$", "p", "->", "filename", ",", "$", "m", ")", ")", "{", "// modify filename", "$", "p", "->", "filename", ".=", "'.pgp'", ";", "// flag the part, it will be decrypted when needed", "unset", "(", "$", "p", "->", "need_decryption", ")", ";", "}", "}", "}", "}" ]
Handler for plain encrypted message. @param array Reference to hook's parameters @param string Message (part) body @param string Body prefix (additional text before the encrypted block)
[ "Handler", "for", "plain", "encrypted", "message", "." ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/plugins/enigma/lib/enigma_engine.php#L699-L778
train
i-MSCP/roundcube
roundcubemail/plugins/enigma/lib/enigma_engine.php
enigma_engine.pgp_verify
private function pgp_verify(&$msg_body, $sig_body = null) { // @TODO: Handle big bodies using (temp) files $sig = $this->pgp_driver->verify($msg_body, $sig_body); if (($sig instanceof enigma_error) && $sig->getCode() != enigma_error::KEYNOTFOUND) { self::raise_error($sig, __LINE__); } return $sig; }
php
private function pgp_verify(&$msg_body, $sig_body = null) { // @TODO: Handle big bodies using (temp) files $sig = $this->pgp_driver->verify($msg_body, $sig_body); if (($sig instanceof enigma_error) && $sig->getCode() != enigma_error::KEYNOTFOUND) { self::raise_error($sig, __LINE__); } return $sig; }
[ "private", "function", "pgp_verify", "(", "&", "$", "msg_body", ",", "$", "sig_body", "=", "null", ")", "{", "// @TODO: Handle big bodies using (temp) files", "$", "sig", "=", "$", "this", "->", "pgp_driver", "->", "verify", "(", "$", "msg_body", ",", "$", "sig_body", ")", ";", "if", "(", "(", "$", "sig", "instanceof", "enigma_error", ")", "&&", "$", "sig", "->", "getCode", "(", ")", "!=", "enigma_error", "::", "KEYNOTFOUND", ")", "{", "self", "::", "raise_error", "(", "$", "sig", ",", "__LINE__", ")", ";", "}", "return", "$", "sig", ";", "}" ]
PGP signature verification. @param mixed Message body @param mixed Signature body (for MIME messages) @return mixed enigma_signature or enigma_error
[ "PGP", "signature", "verification", "." ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/plugins/enigma/lib/enigma_engine.php#L860-L870
train
i-MSCP/roundcube
roundcubemail/plugins/enigma/lib/enigma_engine.php
enigma_engine.pgp_decrypt
private function pgp_decrypt(&$msg_body, &$signature = null) { // @TODO: Handle big bodies using (temp) files $keys = $this->get_passwords(); $result = $this->pgp_driver->decrypt($msg_body, $keys, $signature); if ($result instanceof enigma_error) { if ($result->getCode() != enigma_error::KEYNOTFOUND) { self::raise_error($result, __LINE__); } return $result; } $msg_body = $result; return true; }
php
private function pgp_decrypt(&$msg_body, &$signature = null) { // @TODO: Handle big bodies using (temp) files $keys = $this->get_passwords(); $result = $this->pgp_driver->decrypt($msg_body, $keys, $signature); if ($result instanceof enigma_error) { if ($result->getCode() != enigma_error::KEYNOTFOUND) { self::raise_error($result, __LINE__); } return $result; } $msg_body = $result; return true; }
[ "private", "function", "pgp_decrypt", "(", "&", "$", "msg_body", ",", "&", "$", "signature", "=", "null", ")", "{", "// @TODO: Handle big bodies using (temp) files", "$", "keys", "=", "$", "this", "->", "get_passwords", "(", ")", ";", "$", "result", "=", "$", "this", "->", "pgp_driver", "->", "decrypt", "(", "$", "msg_body", ",", "$", "keys", ",", "$", "signature", ")", ";", "if", "(", "$", "result", "instanceof", "enigma_error", ")", "{", "if", "(", "$", "result", "->", "getCode", "(", ")", "!=", "enigma_error", "::", "KEYNOTFOUND", ")", "{", "self", "::", "raise_error", "(", "$", "result", ",", "__LINE__", ")", ";", "}", "return", "$", "result", ";", "}", "$", "msg_body", "=", "$", "result", ";", "return", "true", ";", "}" ]
PGP message decryption. @param mixed &$msg_body Message body @param enigma_signature &$signature Signature verification result @return mixed True or enigma_error
[ "PGP", "message", "decryption", "." ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/plugins/enigma/lib/enigma_engine.php#L880-L897
train
i-MSCP/roundcube
roundcubemail/plugins/enigma/lib/enigma_engine.php
enigma_engine.pgp_sign
private function pgp_sign(&$msg_body, $key, $mode = null) { // @TODO: Handle big bodies using (temp) files $result = $this->pgp_driver->sign($msg_body, $key, $mode); if ($result instanceof enigma_error) { if ($result->getCode() != enigma_error::KEYNOTFOUND) { self::raise_error($result, __LINE__); } return $result; } $msg_body = $result; return true; }
php
private function pgp_sign(&$msg_body, $key, $mode = null) { // @TODO: Handle big bodies using (temp) files $result = $this->pgp_driver->sign($msg_body, $key, $mode); if ($result instanceof enigma_error) { if ($result->getCode() != enigma_error::KEYNOTFOUND) { self::raise_error($result, __LINE__); } return $result; } $msg_body = $result; return true; }
[ "private", "function", "pgp_sign", "(", "&", "$", "msg_body", ",", "$", "key", ",", "$", "mode", "=", "null", ")", "{", "// @TODO: Handle big bodies using (temp) files", "$", "result", "=", "$", "this", "->", "pgp_driver", "->", "sign", "(", "$", "msg_body", ",", "$", "key", ",", "$", "mode", ")", ";", "if", "(", "$", "result", "instanceof", "enigma_error", ")", "{", "if", "(", "$", "result", "->", "getCode", "(", ")", "!=", "enigma_error", "::", "KEYNOTFOUND", ")", "{", "self", "::", "raise_error", "(", "$", "result", ",", "__LINE__", ")", ";", "}", "return", "$", "result", ";", "}", "$", "msg_body", "=", "$", "result", ";", "return", "true", ";", "}" ]
PGP message signing @param mixed Message body @param enigma_key The key (with passphrase) @param int Signing mode @return mixed True or enigma_error
[ "PGP", "message", "signing" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/plugins/enigma/lib/enigma_engine.php#L908-L924
train
i-MSCP/roundcube
roundcubemail/plugins/enigma/lib/enigma_engine.php
enigma_engine.pgp_encrypt
private function pgp_encrypt(&$msg_body, $keys, $sign_key = null, $sign_pass = null) { // @TODO: Handle big bodies using (temp) files $result = $this->pgp_driver->encrypt($msg_body, $keys, $sign_key, $sign_pass); if ($result instanceof enigma_error) { if ($result->getCode() != enigma_error::KEYNOTFOUND) { self::raise_error($result, __LINE__); } return $result; } $msg_body = $result; return true; }
php
private function pgp_encrypt(&$msg_body, $keys, $sign_key = null, $sign_pass = null) { // @TODO: Handle big bodies using (temp) files $result = $this->pgp_driver->encrypt($msg_body, $keys, $sign_key, $sign_pass); if ($result instanceof enigma_error) { if ($result->getCode() != enigma_error::KEYNOTFOUND) { self::raise_error($result, __LINE__); } return $result; } $msg_body = $result; return true; }
[ "private", "function", "pgp_encrypt", "(", "&", "$", "msg_body", ",", "$", "keys", ",", "$", "sign_key", "=", "null", ",", "$", "sign_pass", "=", "null", ")", "{", "// @TODO: Handle big bodies using (temp) files", "$", "result", "=", "$", "this", "->", "pgp_driver", "->", "encrypt", "(", "$", "msg_body", ",", "$", "keys", ",", "$", "sign_key", ",", "$", "sign_pass", ")", ";", "if", "(", "$", "result", "instanceof", "enigma_error", ")", "{", "if", "(", "$", "result", "->", "getCode", "(", ")", "!=", "enigma_error", "::", "KEYNOTFOUND", ")", "{", "self", "::", "raise_error", "(", "$", "result", ",", "__LINE__", ")", ";", "}", "return", "$", "result", ";", "}", "$", "msg_body", "=", "$", "result", ";", "return", "true", ";", "}" ]
PGP message encrypting @param mixed Message body @param array Keys (array of enigma_key objects) @param string Optional signing Key ID @param string Optional signing Key password @return mixed True or enigma_error
[ "PGP", "message", "encrypting" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/plugins/enigma/lib/enigma_engine.php#L936-L952
train
i-MSCP/roundcube
roundcubemail/plugins/enigma/lib/enigma_engine.php
enigma_engine.list_keys
function list_keys($pattern = '') { $this->load_pgp_driver(); $result = $this->pgp_driver->list_keys($pattern); if ($result instanceof enigma_error) { self::raise_error($result, __LINE__); } return $result; }
php
function list_keys($pattern = '') { $this->load_pgp_driver(); $result = $this->pgp_driver->list_keys($pattern); if ($result instanceof enigma_error) { self::raise_error($result, __LINE__); } return $result; }
[ "function", "list_keys", "(", "$", "pattern", "=", "''", ")", "{", "$", "this", "->", "load_pgp_driver", "(", ")", ";", "$", "result", "=", "$", "this", "->", "pgp_driver", "->", "list_keys", "(", "$", "pattern", ")", ";", "if", "(", "$", "result", "instanceof", "enigma_error", ")", "{", "self", "::", "raise_error", "(", "$", "result", ",", "__LINE__", ")", ";", "}", "return", "$", "result", ";", "}" ]
PGP keys listing. @param mixed Key ID/Name pattern @return mixed Array of keys or enigma_error
[ "PGP", "keys", "listing", "." ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/plugins/enigma/lib/enigma_engine.php#L961-L971
train
i-MSCP/roundcube
roundcubemail/plugins/enigma/lib/enigma_engine.php
enigma_engine.get_key
function get_key($keyid) { $this->load_pgp_driver(); $result = $this->pgp_driver->get_key($keyid); if ($result instanceof enigma_error) { self::raise_error($result, __LINE__); } return $result; }
php
function get_key($keyid) { $this->load_pgp_driver(); $result = $this->pgp_driver->get_key($keyid); if ($result instanceof enigma_error) { self::raise_error($result, __LINE__); } return $result; }
[ "function", "get_key", "(", "$", "keyid", ")", "{", "$", "this", "->", "load_pgp_driver", "(", ")", ";", "$", "result", "=", "$", "this", "->", "pgp_driver", "->", "get_key", "(", "$", "keyid", ")", ";", "if", "(", "$", "result", "instanceof", "enigma_error", ")", "{", "self", "::", "raise_error", "(", "$", "result", ",", "__LINE__", ")", ";", "}", "return", "$", "result", ";", "}" ]
PGP key details. @param mixed Key ID @return mixed enigma_key or enigma_error
[ "PGP", "key", "details", "." ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/plugins/enigma/lib/enigma_engine.php#L1024-L1034
train
i-MSCP/roundcube
roundcubemail/plugins/enigma/lib/enigma_engine.php
enigma_engine.generate_key
function generate_key($data) { $this->load_pgp_driver(); $result = $this->pgp_driver->gen_key($data); if ($result instanceof enigma_error) { self::raise_error($result, __LINE__); } return $result; }
php
function generate_key($data) { $this->load_pgp_driver(); $result = $this->pgp_driver->gen_key($data); if ($result instanceof enigma_error) { self::raise_error($result, __LINE__); } return $result; }
[ "function", "generate_key", "(", "$", "data", ")", "{", "$", "this", "->", "load_pgp_driver", "(", ")", ";", "$", "result", "=", "$", "this", "->", "pgp_driver", "->", "gen_key", "(", "$", "data", ")", ";", "if", "(", "$", "result", "instanceof", "enigma_error", ")", "{", "self", "::", "raise_error", "(", "$", "result", ",", "__LINE__", ")", ";", "}", "return", "$", "result", ";", "}" ]
PGP keys pair generation. @param array Key pair parameters @return mixed enigma_key or enigma_error
[ "PGP", "keys", "pair", "generation", "." ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/plugins/enigma/lib/enigma_engine.php#L1062-L1072
train
i-MSCP/roundcube
roundcubemail/plugins/enigma/lib/enigma_engine.php
enigma_engine.get_passwords
function get_passwords() { if ($config = $_SESSION['enigma_pass']) { $config = $this->rc->decrypt($config); $config = @unserialize($config); } $threshold = $this->password_time ? time() - $this->password_time : 0; $keys = array(); // delete expired passwords foreach ((array) $config as $key => $value) { if ($threshold && $value[1] < $threshold) { unset($config[$key]); $modified = true; } else { $keys[$key] = $value[0]; } } if ($modified) { $_SESSION['enigma_pass'] = $this->rc->encrypt(serialize($config)); } return $keys; }
php
function get_passwords() { if ($config = $_SESSION['enigma_pass']) { $config = $this->rc->decrypt($config); $config = @unserialize($config); } $threshold = $this->password_time ? time() - $this->password_time : 0; $keys = array(); // delete expired passwords foreach ((array) $config as $key => $value) { if ($threshold && $value[1] < $threshold) { unset($config[$key]); $modified = true; } else { $keys[$key] = $value[0]; } } if ($modified) { $_SESSION['enigma_pass'] = $this->rc->encrypt(serialize($config)); } return $keys; }
[ "function", "get_passwords", "(", ")", "{", "if", "(", "$", "config", "=", "$", "_SESSION", "[", "'enigma_pass'", "]", ")", "{", "$", "config", "=", "$", "this", "->", "rc", "->", "decrypt", "(", "$", "config", ")", ";", "$", "config", "=", "@", "unserialize", "(", "$", "config", ")", ";", "}", "$", "threshold", "=", "$", "this", "->", "password_time", "?", "time", "(", ")", "-", "$", "this", "->", "password_time", ":", "0", ";", "$", "keys", "=", "array", "(", ")", ";", "// delete expired passwords", "foreach", "(", "(", "array", ")", "$", "config", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "$", "threshold", "&&", "$", "value", "[", "1", "]", "<", "$", "threshold", ")", "{", "unset", "(", "$", "config", "[", "$", "key", "]", ")", ";", "$", "modified", "=", "true", ";", "}", "else", "{", "$", "keys", "[", "$", "key", "]", "=", "$", "value", "[", "0", "]", ";", "}", "}", "if", "(", "$", "modified", ")", "{", "$", "_SESSION", "[", "'enigma_pass'", "]", "=", "$", "this", "->", "rc", "->", "encrypt", "(", "serialize", "(", "$", "config", ")", ")", ";", "}", "return", "$", "keys", ";", "}" ]
Returns currently stored passwords
[ "Returns", "currently", "stored", "passwords" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/plugins/enigma/lib/enigma_engine.php#L1157-L1183
train
i-MSCP/roundcube
roundcubemail/plugins/enigma/lib/enigma_engine.php
enigma_engine.get_part_body
private function get_part_body($msg, $part) { // @TODO: Handle big bodies using file handles // This is a special case when we want to get the whole body // using direct IMAP access, in other cases we prefer // rcube_message::get_part_body() as the body may be already in memory if (!$part->mime_id) { // fake the size which may be empty for multipart/* parts // otherwise get_message_part() below will fail if (!$part->size) { $reset = true; $part->size = 1; } $storage = $this->rc->get_storage(); $body = $storage->get_message_part($msg->uid, $part->mime_id, $part, null, null, true, 0, false); if ($reset) { $part->size = 0; } } else { $body = $msg->get_part_body($part->mime_id, false); // Convert charset to get rid of possible non-ascii characters (#5962) if ($part->charset && stripos($part->charset, 'ASCII') === false) { $body = rcube_charset::convert($body, $part->charset, 'US-ASCII'); } } return $body; }
php
private function get_part_body($msg, $part) { // @TODO: Handle big bodies using file handles // This is a special case when we want to get the whole body // using direct IMAP access, in other cases we prefer // rcube_message::get_part_body() as the body may be already in memory if (!$part->mime_id) { // fake the size which may be empty for multipart/* parts // otherwise get_message_part() below will fail if (!$part->size) { $reset = true; $part->size = 1; } $storage = $this->rc->get_storage(); $body = $storage->get_message_part($msg->uid, $part->mime_id, $part, null, null, true, 0, false); if ($reset) { $part->size = 0; } } else { $body = $msg->get_part_body($part->mime_id, false); // Convert charset to get rid of possible non-ascii characters (#5962) if ($part->charset && stripos($part->charset, 'ASCII') === false) { $body = rcube_charset::convert($body, $part->charset, 'US-ASCII'); } } return $body; }
[ "private", "function", "get_part_body", "(", "$", "msg", ",", "$", "part", ")", "{", "// @TODO: Handle big bodies using file handles", "// This is a special case when we want to get the whole body", "// using direct IMAP access, in other cases we prefer", "// rcube_message::get_part_body() as the body may be already in memory", "if", "(", "!", "$", "part", "->", "mime_id", ")", "{", "// fake the size which may be empty for multipart/* parts", "// otherwise get_message_part() below will fail", "if", "(", "!", "$", "part", "->", "size", ")", "{", "$", "reset", "=", "true", ";", "$", "part", "->", "size", "=", "1", ";", "}", "$", "storage", "=", "$", "this", "->", "rc", "->", "get_storage", "(", ")", ";", "$", "body", "=", "$", "storage", "->", "get_message_part", "(", "$", "msg", "->", "uid", ",", "$", "part", "->", "mime_id", ",", "$", "part", ",", "null", ",", "null", ",", "true", ",", "0", ",", "false", ")", ";", "if", "(", "$", "reset", ")", "{", "$", "part", "->", "size", "=", "0", ";", "}", "}", "else", "{", "$", "body", "=", "$", "msg", "->", "get_part_body", "(", "$", "part", "->", "mime_id", ",", "false", ")", ";", "// Convert charset to get rid of possible non-ascii characters (#5962)", "if", "(", "$", "part", "->", "charset", "&&", "stripos", "(", "$", "part", "->", "charset", ",", "'ASCII'", ")", "===", "false", ")", "{", "$", "body", "=", "rcube_charset", "::", "convert", "(", "$", "body", ",", "$", "part", "->", "charset", ",", "'US-ASCII'", ")", ";", "}", "}", "return", "$", "body", ";", "}" ]
Get message part body. @param rcube_message Message object @param rcube_message_part Message part
[ "Get", "message", "part", "body", "." ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/plugins/enigma/lib/enigma_engine.php#L1191-L1224
train
i-MSCP/roundcube
roundcubemail/plugins/enigma/lib/enigma_engine.php
enigma_engine.parse_body
private function parse_body(&$body) { // Mail_mimeDecode need \r\n end-line, but gpg may return \n $body = preg_replace('/\r?\n/', "\r\n", $body); // parse the body into structure $struct = rcube_mime::parse_message($body); return $struct; }
php
private function parse_body(&$body) { // Mail_mimeDecode need \r\n end-line, but gpg may return \n $body = preg_replace('/\r?\n/', "\r\n", $body); // parse the body into structure $struct = rcube_mime::parse_message($body); return $struct; }
[ "private", "function", "parse_body", "(", "&", "$", "body", ")", "{", "// Mail_mimeDecode need \\r\\n end-line, but gpg may return \\n", "$", "body", "=", "preg_replace", "(", "'/\\r?\\n/'", ",", "\"\\r\\n\"", ",", "$", "body", ")", ";", "// parse the body into structure", "$", "struct", "=", "rcube_mime", "::", "parse_message", "(", "$", "body", ")", ";", "return", "$", "struct", ";", "}" ]
Parse decrypted message body into structure @param string Message body @return array Message structure
[ "Parse", "decrypted", "message", "body", "into", "structure" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/plugins/enigma/lib/enigma_engine.php#L1233-L1242
train
i-MSCP/roundcube
roundcubemail/plugins/enigma/lib/enigma_engine.php
enigma_engine.modify_structure
private function modify_structure(&$p, $struct, $size = 0) { // modify mime_parts property of the message object $old_id = $p['structure']->mime_id; foreach (array_keys($p['object']->mime_parts) as $idx) { if (!$old_id || $idx == $old_id || strpos($idx, $old_id . '.') === 0) { unset($p['object']->mime_parts[$idx]); } } // set some part params used by Roundcube core $struct->headers = array_merge($p['structure']->headers, $struct->headers); $struct->size = $size; $struct->filename = $p['structure']->filename; // modify the new structure to be correctly handled by Roundcube $this->modify_structure_part($struct, $p['object'], $old_id); // replace old structure with the new one $p['structure'] = $struct; $p['mimetype'] = $struct->mimetype; }
php
private function modify_structure(&$p, $struct, $size = 0) { // modify mime_parts property of the message object $old_id = $p['structure']->mime_id; foreach (array_keys($p['object']->mime_parts) as $idx) { if (!$old_id || $idx == $old_id || strpos($idx, $old_id . '.') === 0) { unset($p['object']->mime_parts[$idx]); } } // set some part params used by Roundcube core $struct->headers = array_merge($p['structure']->headers, $struct->headers); $struct->size = $size; $struct->filename = $p['structure']->filename; // modify the new structure to be correctly handled by Roundcube $this->modify_structure_part($struct, $p['object'], $old_id); // replace old structure with the new one $p['structure'] = $struct; $p['mimetype'] = $struct->mimetype; }
[ "private", "function", "modify_structure", "(", "&", "$", "p", ",", "$", "struct", ",", "$", "size", "=", "0", ")", "{", "// modify mime_parts property of the message object", "$", "old_id", "=", "$", "p", "[", "'structure'", "]", "->", "mime_id", ";", "foreach", "(", "array_keys", "(", "$", "p", "[", "'object'", "]", "->", "mime_parts", ")", "as", "$", "idx", ")", "{", "if", "(", "!", "$", "old_id", "||", "$", "idx", "==", "$", "old_id", "||", "strpos", "(", "$", "idx", ",", "$", "old_id", ".", "'.'", ")", "===", "0", ")", "{", "unset", "(", "$", "p", "[", "'object'", "]", "->", "mime_parts", "[", "$", "idx", "]", ")", ";", "}", "}", "// set some part params used by Roundcube core", "$", "struct", "->", "headers", "=", "array_merge", "(", "$", "p", "[", "'structure'", "]", "->", "headers", ",", "$", "struct", "->", "headers", ")", ";", "$", "struct", "->", "size", "=", "$", "size", ";", "$", "struct", "->", "filename", "=", "$", "p", "[", "'structure'", "]", "->", "filename", ";", "// modify the new structure to be correctly handled by Roundcube", "$", "this", "->", "modify_structure_part", "(", "$", "struct", ",", "$", "p", "[", "'object'", "]", ",", "$", "old_id", ")", ";", "// replace old structure with the new one", "$", "p", "[", "'structure'", "]", "=", "$", "struct", ";", "$", "p", "[", "'mimetype'", "]", "=", "$", "struct", "->", "mimetype", ";", "}" ]
Replace message encrypted structure with decrypted message structure @param array Hook arguments @param rcube_message_part Part structure @param int Part size
[ "Replace", "message", "encrypted", "structure", "with", "decrypted", "message", "structure" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/plugins/enigma/lib/enigma_engine.php#L1251-L1273
train
i-MSCP/roundcube
roundcubemail/plugins/enigma/lib/enigma_engine.php
enigma_engine.modify_structure_part
private function modify_structure_part($part, $msg, $old_id) { // never cache the body $part->body_modified = true; $part->encoding = 'stream'; // modify part identifier if ($old_id) { $part->mime_id = !$part->mime_id ? $old_id : ($old_id . '.' . $part->mime_id); } // Cache the fact it was decrypted $this->encrypted_parts[] = $part->mime_id; $msg->mime_parts[$part->mime_id] = $part; // modify sub-parts foreach ((array) $part->parts as $p) { $this->modify_structure_part($p, $msg, $old_id); } }
php
private function modify_structure_part($part, $msg, $old_id) { // never cache the body $part->body_modified = true; $part->encoding = 'stream'; // modify part identifier if ($old_id) { $part->mime_id = !$part->mime_id ? $old_id : ($old_id . '.' . $part->mime_id); } // Cache the fact it was decrypted $this->encrypted_parts[] = $part->mime_id; $msg->mime_parts[$part->mime_id] = $part; // modify sub-parts foreach ((array) $part->parts as $p) { $this->modify_structure_part($p, $msg, $old_id); } }
[ "private", "function", "modify_structure_part", "(", "$", "part", ",", "$", "msg", ",", "$", "old_id", ")", "{", "// never cache the body", "$", "part", "->", "body_modified", "=", "true", ";", "$", "part", "->", "encoding", "=", "'stream'", ";", "// modify part identifier", "if", "(", "$", "old_id", ")", "{", "$", "part", "->", "mime_id", "=", "!", "$", "part", "->", "mime_id", "?", "$", "old_id", ":", "(", "$", "old_id", ".", "'.'", ".", "$", "part", "->", "mime_id", ")", ";", "}", "// Cache the fact it was decrypted", "$", "this", "->", "encrypted_parts", "[", "]", "=", "$", "part", "->", "mime_id", ";", "$", "msg", "->", "mime_parts", "[", "$", "part", "->", "mime_id", "]", "=", "$", "part", ";", "// modify sub-parts", "foreach", "(", "(", "array", ")", "$", "part", "->", "parts", "as", "$", "p", ")", "{", "$", "this", "->", "modify_structure_part", "(", "$", "p", ",", "$", "msg", ",", "$", "old_id", ")", ";", "}", "}" ]
Modify decrypted message part @param rcube_message_part @param rcube_message
[ "Modify", "decrypted", "message", "part" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/plugins/enigma/lib/enigma_engine.php#L1281-L1300
train
i-MSCP/roundcube
roundcubemail/plugins/enigma/lib/enigma_engine.php
enigma_engine.delete_user_data
public function delete_user_data($username) { $homedir = $this->rc->config->get('enigma_pgp_homedir', INSTALL_PATH . 'plugins/enigma/home'); $homedir .= DIRECTORY_SEPARATOR . $username; return file_exists($homedir) ? self::delete_dir($homedir) : true; }
php
public function delete_user_data($username) { $homedir = $this->rc->config->get('enigma_pgp_homedir', INSTALL_PATH . 'plugins/enigma/home'); $homedir .= DIRECTORY_SEPARATOR . $username; return file_exists($homedir) ? self::delete_dir($homedir) : true; }
[ "public", "function", "delete_user_data", "(", "$", "username", ")", "{", "$", "homedir", "=", "$", "this", "->", "rc", "->", "config", "->", "get", "(", "'enigma_pgp_homedir'", ",", "INSTALL_PATH", ".", "'plugins/enigma/home'", ")", ";", "$", "homedir", ".=", "DIRECTORY_SEPARATOR", ".", "$", "username", ";", "return", "file_exists", "(", "$", "homedir", ")", "?", "self", "::", "delete_dir", "(", "$", "homedir", ")", ":", "true", ";", "}" ]
Removes all user keys and assigned data @param string Username @return bool True on success, False on failure
[ "Removes", "all", "user", "keys", "and", "assigned", "data" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/plugins/enigma/lib/enigma_engine.php#L1352-L1358
train
i-MSCP/roundcube
roundcubemail/plugins/enigma/lib/enigma_engine.php
enigma_engine.delete_dir
public static function delete_dir($dir) { // This code can be executed from command line, make sure // we have permissions to delete keys directory if (!is_writable($dir)) { rcube::raise_error("Unable to delete $dir", false, true); return false; } if ($content = scandir($dir)) { foreach ($content as $filename) { if ($filename != '.' && $filename != '..') { $filename = $dir . DIRECTORY_SEPARATOR . $filename; if (is_dir($filename)) { self::delete_dir($filename); } else { unlink($filename); } } } rmdir($dir); } return true; }
php
public static function delete_dir($dir) { // This code can be executed from command line, make sure // we have permissions to delete keys directory if (!is_writable($dir)) { rcube::raise_error("Unable to delete $dir", false, true); return false; } if ($content = scandir($dir)) { foreach ($content as $filename) { if ($filename != '.' && $filename != '..') { $filename = $dir . DIRECTORY_SEPARATOR . $filename; if (is_dir($filename)) { self::delete_dir($filename); } else { unlink($filename); } } } rmdir($dir); } return true; }
[ "public", "static", "function", "delete_dir", "(", "$", "dir", ")", "{", "// This code can be executed from command line, make sure", "// we have permissions to delete keys directory", "if", "(", "!", "is_writable", "(", "$", "dir", ")", ")", "{", "rcube", "::", "raise_error", "(", "\"Unable to delete $dir\"", ",", "false", ",", "true", ")", ";", "return", "false", ";", "}", "if", "(", "$", "content", "=", "scandir", "(", "$", "dir", ")", ")", "{", "foreach", "(", "$", "content", "as", "$", "filename", ")", "{", "if", "(", "$", "filename", "!=", "'.'", "&&", "$", "filename", "!=", "'..'", ")", "{", "$", "filename", "=", "$", "dir", ".", "DIRECTORY_SEPARATOR", ".", "$", "filename", ";", "if", "(", "is_dir", "(", "$", "filename", ")", ")", "{", "self", "::", "delete_dir", "(", "$", "filename", ")", ";", "}", "else", "{", "unlink", "(", "$", "filename", ")", ";", "}", "}", "}", "rmdir", "(", "$", "dir", ")", ";", "}", "return", "true", ";", "}" ]
Recursive method to remove directory with its content @param string Directory
[ "Recursive", "method", "to", "remove", "directory", "with", "its", "content" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/plugins/enigma/lib/enigma_engine.php#L1365-L1392
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_db_mysql.php
rcube_db_mysql.dsn_string
protected function dsn_string($dsn) { $params = array(); $result = 'mysql:'; if ($dsn['database']) { $params[] = 'dbname=' . $dsn['database']; } if ($dsn['hostspec']) { $params[] = 'host=' . $dsn['hostspec']; } if ($dsn['port']) { $params[] = 'port=' . $dsn['port']; } if ($dsn['socket']) { $params[] = 'unix_socket=' . $dsn['socket']; } $params[] = 'charset=utf8'; if (!empty($params)) { $result .= implode(';', $params); } return $result; }
php
protected function dsn_string($dsn) { $params = array(); $result = 'mysql:'; if ($dsn['database']) { $params[] = 'dbname=' . $dsn['database']; } if ($dsn['hostspec']) { $params[] = 'host=' . $dsn['hostspec']; } if ($dsn['port']) { $params[] = 'port=' . $dsn['port']; } if ($dsn['socket']) { $params[] = 'unix_socket=' . $dsn['socket']; } $params[] = 'charset=utf8'; if (!empty($params)) { $result .= implode(';', $params); } return $result; }
[ "protected", "function", "dsn_string", "(", "$", "dsn", ")", "{", "$", "params", "=", "array", "(", ")", ";", "$", "result", "=", "'mysql:'", ";", "if", "(", "$", "dsn", "[", "'database'", "]", ")", "{", "$", "params", "[", "]", "=", "'dbname='", ".", "$", "dsn", "[", "'database'", "]", ";", "}", "if", "(", "$", "dsn", "[", "'hostspec'", "]", ")", "{", "$", "params", "[", "]", "=", "'host='", ".", "$", "dsn", "[", "'hostspec'", "]", ";", "}", "if", "(", "$", "dsn", "[", "'port'", "]", ")", "{", "$", "params", "[", "]", "=", "'port='", ".", "$", "dsn", "[", "'port'", "]", ";", "}", "if", "(", "$", "dsn", "[", "'socket'", "]", ")", "{", "$", "params", "[", "]", "=", "'unix_socket='", ".", "$", "dsn", "[", "'socket'", "]", ";", "}", "$", "params", "[", "]", "=", "'charset=utf8'", ";", "if", "(", "!", "empty", "(", "$", "params", ")", ")", "{", "$", "result", ".=", "implode", "(", "';'", ",", "$", "params", ")", ";", "}", "return", "$", "result", ";", "}" ]
Returns PDO DSN string from DSN array @param array $dsn DSN parameters @return string Connection string
[ "Returns", "PDO", "DSN", "string", "from", "DSN", "array" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_db_mysql.php#L82-L110
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_db_mysql.php
rcube_db_mysql.handle_error
protected function handle_error($query) { $error = $this->dbh->errorInfo(); // retry after "Deadlock found when trying to get lock" errors $retries = 2; while ($error[1] == 1213 && $retries >= 0) { usleep(50000); // wait 50 ms $result = $this->dbh->query($query); if ($result !== false) { return $result; } $error = $this->dbh->errorInfo(); $retries--; } return parent::handle_error($query); }
php
protected function handle_error($query) { $error = $this->dbh->errorInfo(); // retry after "Deadlock found when trying to get lock" errors $retries = 2; while ($error[1] == 1213 && $retries >= 0) { usleep(50000); // wait 50 ms $result = $this->dbh->query($query); if ($result !== false) { return $result; } $error = $this->dbh->errorInfo(); $retries--; } return parent::handle_error($query); }
[ "protected", "function", "handle_error", "(", "$", "query", ")", "{", "$", "error", "=", "$", "this", "->", "dbh", "->", "errorInfo", "(", ")", ";", "// retry after \"Deadlock found when trying to get lock\" errors", "$", "retries", "=", "2", ";", "while", "(", "$", "error", "[", "1", "]", "==", "1213", "&&", "$", "retries", ">=", "0", ")", "{", "usleep", "(", "50000", ")", ";", "// wait 50 ms", "$", "result", "=", "$", "this", "->", "dbh", "->", "query", "(", "$", "query", ")", ";", "if", "(", "$", "result", "!==", "false", ")", "{", "return", "$", "result", ";", "}", "$", "error", "=", "$", "this", "->", "dbh", "->", "errorInfo", "(", ")", ";", "$", "retries", "--", ";", "}", "return", "parent", "::", "handle_error", "(", "$", "query", ")", ";", "}" ]
Handle DB errors, re-issue the query on deadlock errors from InnoDB row-level locking @param string Query that triggered the error @return mixed Result to be stored and returned
[ "Handle", "DB", "errors", "re", "-", "issue", "the", "query", "on", "deadlock", "errors", "from", "InnoDB", "row", "-", "level", "locking" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_db_mysql.php#L220-L237
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_utils.php
rcube_utils.setcookie
public static function setcookie($name, $value, $exp = 0) { if (headers_sent()) { return; } $cookie = session_get_cookie_params(); $secure = $cookie['secure'] || self::https_check(); setcookie($name, $value, $exp, $cookie['path'], $cookie['domain'], $secure, true); }
php
public static function setcookie($name, $value, $exp = 0) { if (headers_sent()) { return; } $cookie = session_get_cookie_params(); $secure = $cookie['secure'] || self::https_check(); setcookie($name, $value, $exp, $cookie['path'], $cookie['domain'], $secure, true); }
[ "public", "static", "function", "setcookie", "(", "$", "name", ",", "$", "value", ",", "$", "exp", "=", "0", ")", "{", "if", "(", "headers_sent", "(", ")", ")", "{", "return", ";", "}", "$", "cookie", "=", "session_get_cookie_params", "(", ")", ";", "$", "secure", "=", "$", "cookie", "[", "'secure'", "]", "||", "self", "::", "https_check", "(", ")", ";", "setcookie", "(", "$", "name", ",", "$", "value", ",", "$", "exp", ",", "$", "cookie", "[", "'path'", "]", ",", "$", "cookie", "[", "'domain'", "]", ",", "$", "secure", ",", "true", ")", ";", "}" ]
Helper method to set a cookie with the current path and host settings @param string Cookie name @param string Cookie value @param string Expiration time
[ "Helper", "method", "to", "set", "a", "cookie", "with", "the", "current", "path", "and", "host", "settings" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_utils.php#L44-L54
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_utils.php
rcube_utils.check_email
public static function check_email($email, $dns_check=true) { // Check for invalid characters if (preg_match('/[\x00-\x1F\x7F-\xFF]/', $email)) { return false; } // Check for length limit specified by RFC 5321 (#1486453) if (strlen($email) > 254) { return false; } $email_array = explode('@', $email); // Check that there's one @ symbol if (count($email_array) < 2) { return false; } $domain_part = array_pop($email_array); $local_part = implode('@', $email_array); // from PEAR::Validate $regexp = '&^(?: ("\s*(?:[^"\f\n\r\t\v\b\s]+\s*)+")| #1 quoted name ([-\w!\#\$%\&\'*+~/^`|{}=]+(?:\.[-\w!\#\$%\&\'*+~/^`|{}=]+)*)) #2 OR dot-atom (RFC5322) $&xi'; if (!preg_match($regexp, $local_part)) { return false; } // Validate domain part if (preg_match('/^\[((IPv6:[0-9a-f:.]+)|([0-9.]+))\]$/i', $domain_part, $matches)) { return self::check_ip(preg_replace('/^IPv6:/i', '', $matches[1])); // valid IPv4 or IPv6 address } else { // If not an IP address $domain_array = explode('.', $domain_part); // Not enough parts to be a valid domain if (count($domain_array) < 2) { return false; } foreach ($domain_array as $part) { if (!preg_match('/^((xn--)?([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]))$/', $part)) { return false; } } // last domain part $last_part = array_pop($domain_array); if (strpos($last_part, 'xn--') !== 0 && preg_match('/[^a-zA-Z]/', $last_part)) { return false; } $rcube = rcube::get_instance(); if (!$dns_check || !function_exists('checkdnsrr') || !$rcube->config->get('email_dns_check')) { return true; } // Check DNS record(s) // Note: We can't use ANY (#6581) foreach (array('A', 'MX', 'CNAME', 'AAAA') as $type) { if (checkdnsrr($domain_part, $type)) { return true; } } } return false; }
php
public static function check_email($email, $dns_check=true) { // Check for invalid characters if (preg_match('/[\x00-\x1F\x7F-\xFF]/', $email)) { return false; } // Check for length limit specified by RFC 5321 (#1486453) if (strlen($email) > 254) { return false; } $email_array = explode('@', $email); // Check that there's one @ symbol if (count($email_array) < 2) { return false; } $domain_part = array_pop($email_array); $local_part = implode('@', $email_array); // from PEAR::Validate $regexp = '&^(?: ("\s*(?:[^"\f\n\r\t\v\b\s]+\s*)+")| #1 quoted name ([-\w!\#\$%\&\'*+~/^`|{}=]+(?:\.[-\w!\#\$%\&\'*+~/^`|{}=]+)*)) #2 OR dot-atom (RFC5322) $&xi'; if (!preg_match($regexp, $local_part)) { return false; } // Validate domain part if (preg_match('/^\[((IPv6:[0-9a-f:.]+)|([0-9.]+))\]$/i', $domain_part, $matches)) { return self::check_ip(preg_replace('/^IPv6:/i', '', $matches[1])); // valid IPv4 or IPv6 address } else { // If not an IP address $domain_array = explode('.', $domain_part); // Not enough parts to be a valid domain if (count($domain_array) < 2) { return false; } foreach ($domain_array as $part) { if (!preg_match('/^((xn--)?([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]))$/', $part)) { return false; } } // last domain part $last_part = array_pop($domain_array); if (strpos($last_part, 'xn--') !== 0 && preg_match('/[^a-zA-Z]/', $last_part)) { return false; } $rcube = rcube::get_instance(); if (!$dns_check || !function_exists('checkdnsrr') || !$rcube->config->get('email_dns_check')) { return true; } // Check DNS record(s) // Note: We can't use ANY (#6581) foreach (array('A', 'MX', 'CNAME', 'AAAA') as $type) { if (checkdnsrr($domain_part, $type)) { return true; } } } return false; }
[ "public", "static", "function", "check_email", "(", "$", "email", ",", "$", "dns_check", "=", "true", ")", "{", "// Check for invalid characters", "if", "(", "preg_match", "(", "'/[\\x00-\\x1F\\x7F-\\xFF]/'", ",", "$", "email", ")", ")", "{", "return", "false", ";", "}", "// Check for length limit specified by RFC 5321 (#1486453)", "if", "(", "strlen", "(", "$", "email", ")", ">", "254", ")", "{", "return", "false", ";", "}", "$", "email_array", "=", "explode", "(", "'@'", ",", "$", "email", ")", ";", "// Check that there's one @ symbol", "if", "(", "count", "(", "$", "email_array", ")", "<", "2", ")", "{", "return", "false", ";", "}", "$", "domain_part", "=", "array_pop", "(", "$", "email_array", ")", ";", "$", "local_part", "=", "implode", "(", "'@'", ",", "$", "email_array", ")", ";", "// from PEAR::Validate", "$", "regexp", "=", "'&^(?:\n (\"\\s*(?:[^\"\\f\\n\\r\\t\\v\\b\\s]+\\s*)+\")| #1 quoted name\n ([-\\w!\\#\\$%\\&\\'*+~/^`|{}=]+(?:\\.[-\\w!\\#\\$%\\&\\'*+~/^`|{}=]+)*)) #2 OR dot-atom (RFC5322)\n $&xi'", ";", "if", "(", "!", "preg_match", "(", "$", "regexp", ",", "$", "local_part", ")", ")", "{", "return", "false", ";", "}", "// Validate domain part", "if", "(", "preg_match", "(", "'/^\\[((IPv6:[0-9a-f:.]+)|([0-9.]+))\\]$/i'", ",", "$", "domain_part", ",", "$", "matches", ")", ")", "{", "return", "self", "::", "check_ip", "(", "preg_replace", "(", "'/^IPv6:/i'", ",", "''", ",", "$", "matches", "[", "1", "]", ")", ")", ";", "// valid IPv4 or IPv6 address", "}", "else", "{", "// If not an IP address", "$", "domain_array", "=", "explode", "(", "'.'", ",", "$", "domain_part", ")", ";", "// Not enough parts to be a valid domain", "if", "(", "count", "(", "$", "domain_array", ")", "<", "2", ")", "{", "return", "false", ";", "}", "foreach", "(", "$", "domain_array", "as", "$", "part", ")", "{", "if", "(", "!", "preg_match", "(", "'/^((xn--)?([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]))$/'", ",", "$", "part", ")", ")", "{", "return", "false", ";", "}", "}", "// last domain part", "$", "last_part", "=", "array_pop", "(", "$", "domain_array", ")", ";", "if", "(", "strpos", "(", "$", "last_part", ",", "'xn--'", ")", "!==", "0", "&&", "preg_match", "(", "'/[^a-zA-Z]/'", ",", "$", "last_part", ")", ")", "{", "return", "false", ";", "}", "$", "rcube", "=", "rcube", "::", "get_instance", "(", ")", ";", "if", "(", "!", "$", "dns_check", "||", "!", "function_exists", "(", "'checkdnsrr'", ")", "||", "!", "$", "rcube", "->", "config", "->", "get", "(", "'email_dns_check'", ")", ")", "{", "return", "true", ";", "}", "// Check DNS record(s)", "// Note: We can't use ANY (#6581)", "foreach", "(", "array", "(", "'A'", ",", "'MX'", ",", "'CNAME'", ",", "'AAAA'", ")", "as", "$", "type", ")", "{", "if", "(", "checkdnsrr", "(", "$", "domain_part", ",", "$", "type", ")", ")", "{", "return", "true", ";", "}", "}", "}", "return", "false", ";", "}" ]
E-mail address validation. @param string $email Email address @param boolean $dns_check True to check dns @return boolean True on success, False if address is invalid
[ "E", "-", "mail", "address", "validation", "." ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_utils.php#L64-L136
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_utils.php
rcube_utils.check_referer
public static function check_referer() { $uri = parse_url($_SERVER['REQUEST_URI']); $referer = parse_url(self::request_header('Referer')); return $referer['host'] == self::request_header('Host') && $referer['path'] == $uri['path']; }
php
public static function check_referer() { $uri = parse_url($_SERVER['REQUEST_URI']); $referer = parse_url(self::request_header('Referer')); return $referer['host'] == self::request_header('Host') && $referer['path'] == $uri['path']; }
[ "public", "static", "function", "check_referer", "(", ")", "{", "$", "uri", "=", "parse_url", "(", "$", "_SERVER", "[", "'REQUEST_URI'", "]", ")", ";", "$", "referer", "=", "parse_url", "(", "self", "::", "request_header", "(", "'Referer'", ")", ")", ";", "return", "$", "referer", "[", "'host'", "]", "==", "self", "::", "request_header", "(", "'Host'", ")", "&&", "$", "referer", "[", "'path'", "]", "==", "$", "uri", "[", "'path'", "]", ";", "}" ]
Check whether the HTTP referer matches the current request @return boolean True if referer is the same host+path, false if not
[ "Check", "whether", "the", "HTTP", "referer", "matches", "the", "current", "request" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_utils.php#L155-L161
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_utils.php
rcube_utils.rep_specialchars_output
public static function rep_specialchars_output($str, $enctype = '', $mode = '', $newlines = true) { static $html_encode_arr = false; static $js_rep_table = false; static $xml_rep_table = false; if (!is_string($str)) { $str = strval($str); } // encode for HTML output if ($enctype == 'html') { if (!$html_encode_arr) { $html_encode_arr = get_html_translation_table(HTML_SPECIALCHARS); unset($html_encode_arr['?']); } $encode_arr = $html_encode_arr; if ($mode == 'remove') { $str = strip_tags($str); } else if ($mode != 'strict') { // don't replace quotes and html tags $ltpos = strpos($str, '<'); if ($ltpos !== false && strpos($str, '>', $ltpos) !== false) { unset($encode_arr['"']); unset($encode_arr['<']); unset($encode_arr['>']); unset($encode_arr['&']); } } $out = strtr($str, $encode_arr); return $newlines ? nl2br($out) : $out; } // if the replace tables for XML and JS are not yet defined if ($js_rep_table === false) { $js_rep_table = $xml_rep_table = array(); $xml_rep_table['&'] = '&amp;'; // can be increased to support more charsets for ($c=160; $c<256; $c++) { $xml_rep_table[chr($c)] = "&#$c;"; } $xml_rep_table['"'] = '&quot;'; $js_rep_table['"'] = '\\"'; $js_rep_table["'"] = "\\'"; $js_rep_table["\\"] = "\\\\"; // Unicode line and paragraph separators (#1486310) $js_rep_table[chr(hexdec('E2')).chr(hexdec('80')).chr(hexdec('A8'))] = '&#8232;'; $js_rep_table[chr(hexdec('E2')).chr(hexdec('80')).chr(hexdec('A9'))] = '&#8233;'; } // encode for javascript use if ($enctype == 'js') { return preg_replace(array("/\r?\n/", "/\r/", '/<\\//'), array('\n', '\n', '<\\/'), strtr($str, $js_rep_table)); } // encode for plaintext if ($enctype == 'text') { return str_replace("\r\n", "\n", $mode == 'remove' ? strip_tags($str) : $str); } if ($enctype == 'url') { return rawurlencode($str); } // encode for XML if ($enctype == 'xml') { return strtr($str, $xml_rep_table); } // no encoding given -> return original string return $str; }
php
public static function rep_specialchars_output($str, $enctype = '', $mode = '', $newlines = true) { static $html_encode_arr = false; static $js_rep_table = false; static $xml_rep_table = false; if (!is_string($str)) { $str = strval($str); } // encode for HTML output if ($enctype == 'html') { if (!$html_encode_arr) { $html_encode_arr = get_html_translation_table(HTML_SPECIALCHARS); unset($html_encode_arr['?']); } $encode_arr = $html_encode_arr; if ($mode == 'remove') { $str = strip_tags($str); } else if ($mode != 'strict') { // don't replace quotes and html tags $ltpos = strpos($str, '<'); if ($ltpos !== false && strpos($str, '>', $ltpos) !== false) { unset($encode_arr['"']); unset($encode_arr['<']); unset($encode_arr['>']); unset($encode_arr['&']); } } $out = strtr($str, $encode_arr); return $newlines ? nl2br($out) : $out; } // if the replace tables for XML and JS are not yet defined if ($js_rep_table === false) { $js_rep_table = $xml_rep_table = array(); $xml_rep_table['&'] = '&amp;'; // can be increased to support more charsets for ($c=160; $c<256; $c++) { $xml_rep_table[chr($c)] = "&#$c;"; } $xml_rep_table['"'] = '&quot;'; $js_rep_table['"'] = '\\"'; $js_rep_table["'"] = "\\'"; $js_rep_table["\\"] = "\\\\"; // Unicode line and paragraph separators (#1486310) $js_rep_table[chr(hexdec('E2')).chr(hexdec('80')).chr(hexdec('A8'))] = '&#8232;'; $js_rep_table[chr(hexdec('E2')).chr(hexdec('80')).chr(hexdec('A9'))] = '&#8233;'; } // encode for javascript use if ($enctype == 'js') { return preg_replace(array("/\r?\n/", "/\r/", '/<\\//'), array('\n', '\n', '<\\/'), strtr($str, $js_rep_table)); } // encode for plaintext if ($enctype == 'text') { return str_replace("\r\n", "\n", $mode == 'remove' ? strip_tags($str) : $str); } if ($enctype == 'url') { return rawurlencode($str); } // encode for XML if ($enctype == 'xml') { return strtr($str, $xml_rep_table); } // no encoding given -> return original string return $str; }
[ "public", "static", "function", "rep_specialchars_output", "(", "$", "str", ",", "$", "enctype", "=", "''", ",", "$", "mode", "=", "''", ",", "$", "newlines", "=", "true", ")", "{", "static", "$", "html_encode_arr", "=", "false", ";", "static", "$", "js_rep_table", "=", "false", ";", "static", "$", "xml_rep_table", "=", "false", ";", "if", "(", "!", "is_string", "(", "$", "str", ")", ")", "{", "$", "str", "=", "strval", "(", "$", "str", ")", ";", "}", "// encode for HTML output", "if", "(", "$", "enctype", "==", "'html'", ")", "{", "if", "(", "!", "$", "html_encode_arr", ")", "{", "$", "html_encode_arr", "=", "get_html_translation_table", "(", "HTML_SPECIALCHARS", ")", ";", "unset", "(", "$", "html_encode_arr", "[", "'?'", "]", ")", ";", "}", "$", "encode_arr", "=", "$", "html_encode_arr", ";", "if", "(", "$", "mode", "==", "'remove'", ")", "{", "$", "str", "=", "strip_tags", "(", "$", "str", ")", ";", "}", "else", "if", "(", "$", "mode", "!=", "'strict'", ")", "{", "// don't replace quotes and html tags", "$", "ltpos", "=", "strpos", "(", "$", "str", ",", "'<'", ")", ";", "if", "(", "$", "ltpos", "!==", "false", "&&", "strpos", "(", "$", "str", ",", "'>'", ",", "$", "ltpos", ")", "!==", "false", ")", "{", "unset", "(", "$", "encode_arr", "[", "'\"'", "]", ")", ";", "unset", "(", "$", "encode_arr", "[", "'<'", "]", ")", ";", "unset", "(", "$", "encode_arr", "[", "'>'", "]", ")", ";", "unset", "(", "$", "encode_arr", "[", "'&'", "]", ")", ";", "}", "}", "$", "out", "=", "strtr", "(", "$", "str", ",", "$", "encode_arr", ")", ";", "return", "$", "newlines", "?", "nl2br", "(", "$", "out", ")", ":", "$", "out", ";", "}", "// if the replace tables for XML and JS are not yet defined", "if", "(", "$", "js_rep_table", "===", "false", ")", "{", "$", "js_rep_table", "=", "$", "xml_rep_table", "=", "array", "(", ")", ";", "$", "xml_rep_table", "[", "'&'", "]", "=", "'&amp;'", ";", "// can be increased to support more charsets", "for", "(", "$", "c", "=", "160", ";", "$", "c", "<", "256", ";", "$", "c", "++", ")", "{", "$", "xml_rep_table", "[", "chr", "(", "$", "c", ")", "]", "=", "\"&#$c;\"", ";", "}", "$", "xml_rep_table", "[", "'\"'", "]", "=", "'&quot;'", ";", "$", "js_rep_table", "[", "'\"'", "]", "=", "'\\\\\"'", ";", "$", "js_rep_table", "[", "\"'\"", "]", "=", "\"\\\\'\"", ";", "$", "js_rep_table", "[", "\"\\\\\"", "]", "=", "\"\\\\\\\\\"", ";", "// Unicode line and paragraph separators (#1486310)", "$", "js_rep_table", "[", "chr", "(", "hexdec", "(", "'E2'", ")", ")", ".", "chr", "(", "hexdec", "(", "'80'", ")", ")", ".", "chr", "(", "hexdec", "(", "'A8'", ")", ")", "]", "=", "'&#8232;'", ";", "$", "js_rep_table", "[", "chr", "(", "hexdec", "(", "'E2'", ")", ")", ".", "chr", "(", "hexdec", "(", "'80'", ")", ")", ".", "chr", "(", "hexdec", "(", "'A9'", ")", ")", "]", "=", "'&#8233;'", ";", "}", "// encode for javascript use", "if", "(", "$", "enctype", "==", "'js'", ")", "{", "return", "preg_replace", "(", "array", "(", "\"/\\r?\\n/\"", ",", "\"/\\r/\"", ",", "'/<\\\\//'", ")", ",", "array", "(", "'\\n'", ",", "'\\n'", ",", "'<\\\\/'", ")", ",", "strtr", "(", "$", "str", ",", "$", "js_rep_table", ")", ")", ";", "}", "// encode for plaintext", "if", "(", "$", "enctype", "==", "'text'", ")", "{", "return", "str_replace", "(", "\"\\r\\n\"", ",", "\"\\n\"", ",", "$", "mode", "==", "'remove'", "?", "strip_tags", "(", "$", "str", ")", ":", "$", "str", ")", ";", "}", "if", "(", "$", "enctype", "==", "'url'", ")", "{", "return", "rawurlencode", "(", "$", "str", ")", ";", "}", "// encode for XML", "if", "(", "$", "enctype", "==", "'xml'", ")", "{", "return", "strtr", "(", "$", "str", ",", "$", "xml_rep_table", ")", ";", "}", "// no encoding given -> return original string", "return", "$", "str", ";", "}" ]
Replacing specials characters to a specific encoding type @param string Input string @param string Encoding type: text|html|xml|js|url @param string Replace mode for tags: show|remove|strict @param boolean Convert newlines @return string The quoted string
[ "Replacing", "specials", "characters", "to", "a", "specific", "encoding", "type" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_utils.php#L173-L251
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_utils.php
rcube_utils.file2class
public static function file2class($mimetype, $filename) { $mimetype = strtolower($mimetype); $filename = strtolower($filename); list($primary, $secondary) = explode('/', $mimetype); $classes = array($primary ?: 'unknown'); if ($secondary) { $classes[] = $secondary; } if (preg_match('/\.([a-z0-9]+)$/', $filename, $m)) { if (!in_array($m[1], $classes)) { $classes[] = $m[1]; } } return join(" ", $classes); }
php
public static function file2class($mimetype, $filename) { $mimetype = strtolower($mimetype); $filename = strtolower($filename); list($primary, $secondary) = explode('/', $mimetype); $classes = array($primary ?: 'unknown'); if ($secondary) { $classes[] = $secondary; } if (preg_match('/\.([a-z0-9]+)$/', $filename, $m)) { if (!in_array($m[1], $classes)) { $classes[] = $m[1]; } } return join(" ", $classes); }
[ "public", "static", "function", "file2class", "(", "$", "mimetype", ",", "$", "filename", ")", "{", "$", "mimetype", "=", "strtolower", "(", "$", "mimetype", ")", ";", "$", "filename", "=", "strtolower", "(", "$", "filename", ")", ";", "list", "(", "$", "primary", ",", "$", "secondary", ")", "=", "explode", "(", "'/'", ",", "$", "mimetype", ")", ";", "$", "classes", "=", "array", "(", "$", "primary", "?", ":", "'unknown'", ")", ";", "if", "(", "$", "secondary", ")", "{", "$", "classes", "[", "]", "=", "$", "secondary", ";", "}", "if", "(", "preg_match", "(", "'/\\.([a-z0-9]+)$/'", ",", "$", "filename", ",", "$", "m", ")", ")", "{", "if", "(", "!", "in_array", "(", "$", "m", "[", "1", "]", ",", "$", "classes", ")", ")", "{", "$", "classes", "[", "]", "=", "$", "m", "[", "1", "]", ";", "}", "}", "return", "join", "(", "\" \"", ",", "$", "classes", ")", ";", "}" ]
Generate CSS classes from mimetype and filename extension @param string $mimetype Mimetype @param string $filename Filename @return string CSS classes separated by space
[ "Generate", "CSS", "classes", "from", "mimetype", "and", "filename", "extension" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_utils.php#L465-L485
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_utils.php
rcube_utils.mem_check
public static function mem_check($need) { $mem_limit = parse_bytes(ini_get('memory_limit')); $memory = function_exists('memory_get_usage') ? memory_get_usage() : 16*1024*1024; // safe value: 16MB return $mem_limit > 0 && $memory + $need > $mem_limit ? false : true; }
php
public static function mem_check($need) { $mem_limit = parse_bytes(ini_get('memory_limit')); $memory = function_exists('memory_get_usage') ? memory_get_usage() : 16*1024*1024; // safe value: 16MB return $mem_limit > 0 && $memory + $need > $mem_limit ? false : true; }
[ "public", "static", "function", "mem_check", "(", "$", "need", ")", "{", "$", "mem_limit", "=", "parse_bytes", "(", "ini_get", "(", "'memory_limit'", ")", ")", ";", "$", "memory", "=", "function_exists", "(", "'memory_get_usage'", ")", "?", "memory_get_usage", "(", ")", ":", "16", "*", "1024", "*", "1024", ";", "// safe value: 16MB", "return", "$", "mem_limit", ">", "0", "&&", "$", "memory", "+", "$", "need", ">", "$", "mem_limit", "?", "false", ":", "true", ";", "}" ]
Check if we can process not exceeding memory_limit @param integer Required amount of memory @return boolean True if memory won't be exceeded, False otherwise
[ "Check", "if", "we", "can", "process", "not", "exceeding", "memory_limit" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_utils.php#L516-L522
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_utils.php
rcube_utils.https_check
public static function https_check($port=null, $use_https=true) { if (!empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) != 'off') { return true; } if (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && strtolower($_SERVER['HTTP_X_FORWARDED_PROTO']) == 'https' && in_array($_SERVER['REMOTE_ADDR'], rcube::get_instance()->config->get('proxy_whitelist', array())) ) { return true; } if ($port && $_SERVER['SERVER_PORT'] == $port) { return true; } if ($use_https && rcube::get_instance()->config->get('use_https')) { return true; } return false; }
php
public static function https_check($port=null, $use_https=true) { if (!empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) != 'off') { return true; } if (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && strtolower($_SERVER['HTTP_X_FORWARDED_PROTO']) == 'https' && in_array($_SERVER['REMOTE_ADDR'], rcube::get_instance()->config->get('proxy_whitelist', array())) ) { return true; } if ($port && $_SERVER['SERVER_PORT'] == $port) { return true; } if ($use_https && rcube::get_instance()->config->get('use_https')) { return true; } return false; }
[ "public", "static", "function", "https_check", "(", "$", "port", "=", "null", ",", "$", "use_https", "=", "true", ")", "{", "if", "(", "!", "empty", "(", "$", "_SERVER", "[", "'HTTPS'", "]", ")", "&&", "strtolower", "(", "$", "_SERVER", "[", "'HTTPS'", "]", ")", "!=", "'off'", ")", "{", "return", "true", ";", "}", "if", "(", "!", "empty", "(", "$", "_SERVER", "[", "'HTTP_X_FORWARDED_PROTO'", "]", ")", "&&", "strtolower", "(", "$", "_SERVER", "[", "'HTTP_X_FORWARDED_PROTO'", "]", ")", "==", "'https'", "&&", "in_array", "(", "$", "_SERVER", "[", "'REMOTE_ADDR'", "]", ",", "rcube", "::", "get_instance", "(", ")", "->", "config", "->", "get", "(", "'proxy_whitelist'", ",", "array", "(", ")", ")", ")", ")", "{", "return", "true", ";", "}", "if", "(", "$", "port", "&&", "$", "_SERVER", "[", "'SERVER_PORT'", "]", "==", "$", "port", ")", "{", "return", "true", ";", "}", "if", "(", "$", "use_https", "&&", "rcube", "::", "get_instance", "(", ")", "->", "config", "->", "get", "(", "'use_https'", ")", ")", "{", "return", "true", ";", "}", "return", "false", ";", "}" ]
Check if working in SSL mode @param integer $port HTTPS port number @param boolean $use_https Enables 'use_https' option checking @return boolean
[ "Check", "if", "working", "in", "SSL", "mode" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_utils.php#L532-L551
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_utils.php
rcube_utils.parse_host
public static function parse_host($name, $host = '') { if (!is_string($name)) { return $name; } // %n - host $n = preg_replace('/:\d+$/', '', $_SERVER['SERVER_NAME']); // %t - host name without first part, e.g. %n=mail.domain.tld, %t=domain.tld $t = preg_replace('/^[^\.]+\./', '', $n); // %d - domain name without first part $d = preg_replace('/^[^\.]+\./', '', $_SERVER['HTTP_HOST']); // %h - IMAP host $h = $_SESSION['storage_host'] ?: $host; // %z - IMAP domain without first part, e.g. %h=imap.domain.tld, %z=domain.tld $z = preg_replace('/^[^\.]+\./', '', $h); // %s - domain name after the '@' from e-mail address provided at login screen. // Returns FALSE if an invalid email is provided if (strpos($name, '%s') !== false) { $user_email = self::get_input_value('_user', self::INPUT_POST); $user_email = self::idn_convert($user_email, true); $matches = preg_match('/(.*)@([a-z0-9\.\-\[\]\:]+)/i', $user_email, $s); if ($matches < 1 || filter_var($s[1]."@".$s[2], FILTER_VALIDATE_EMAIL) === false) { return false; } } return str_replace(array('%n', '%t', '%d', '%h', '%z', '%s'), array($n, $t, $d, $h, $z, $s[2]), $name); }
php
public static function parse_host($name, $host = '') { if (!is_string($name)) { return $name; } // %n - host $n = preg_replace('/:\d+$/', '', $_SERVER['SERVER_NAME']); // %t - host name without first part, e.g. %n=mail.domain.tld, %t=domain.tld $t = preg_replace('/^[^\.]+\./', '', $n); // %d - domain name without first part $d = preg_replace('/^[^\.]+\./', '', $_SERVER['HTTP_HOST']); // %h - IMAP host $h = $_SESSION['storage_host'] ?: $host; // %z - IMAP domain without first part, e.g. %h=imap.domain.tld, %z=domain.tld $z = preg_replace('/^[^\.]+\./', '', $h); // %s - domain name after the '@' from e-mail address provided at login screen. // Returns FALSE if an invalid email is provided if (strpos($name, '%s') !== false) { $user_email = self::get_input_value('_user', self::INPUT_POST); $user_email = self::idn_convert($user_email, true); $matches = preg_match('/(.*)@([a-z0-9\.\-\[\]\:]+)/i', $user_email, $s); if ($matches < 1 || filter_var($s[1]."@".$s[2], FILTER_VALIDATE_EMAIL) === false) { return false; } } return str_replace(array('%n', '%t', '%d', '%h', '%z', '%s'), array($n, $t, $d, $h, $z, $s[2]), $name); }
[ "public", "static", "function", "parse_host", "(", "$", "name", ",", "$", "host", "=", "''", ")", "{", "if", "(", "!", "is_string", "(", "$", "name", ")", ")", "{", "return", "$", "name", ";", "}", "// %n - host", "$", "n", "=", "preg_replace", "(", "'/:\\d+$/'", ",", "''", ",", "$", "_SERVER", "[", "'SERVER_NAME'", "]", ")", ";", "// %t - host name without first part, e.g. %n=mail.domain.tld, %t=domain.tld", "$", "t", "=", "preg_replace", "(", "'/^[^\\.]+\\./'", ",", "''", ",", "$", "n", ")", ";", "// %d - domain name without first part", "$", "d", "=", "preg_replace", "(", "'/^[^\\.]+\\./'", ",", "''", ",", "$", "_SERVER", "[", "'HTTP_HOST'", "]", ")", ";", "// %h - IMAP host", "$", "h", "=", "$", "_SESSION", "[", "'storage_host'", "]", "?", ":", "$", "host", ";", "// %z - IMAP domain without first part, e.g. %h=imap.domain.tld, %z=domain.tld", "$", "z", "=", "preg_replace", "(", "'/^[^\\.]+\\./'", ",", "''", ",", "$", "h", ")", ";", "// %s - domain name after the '@' from e-mail address provided at login screen.", "// Returns FALSE if an invalid email is provided", "if", "(", "strpos", "(", "$", "name", ",", "'%s'", ")", "!==", "false", ")", "{", "$", "user_email", "=", "self", "::", "get_input_value", "(", "'_user'", ",", "self", "::", "INPUT_POST", ")", ";", "$", "user_email", "=", "self", "::", "idn_convert", "(", "$", "user_email", ",", "true", ")", ";", "$", "matches", "=", "preg_match", "(", "'/(.*)@([a-z0-9\\.\\-\\[\\]\\:]+)/i'", ",", "$", "user_email", ",", "$", "s", ")", ";", "if", "(", "$", "matches", "<", "1", "||", "filter_var", "(", "$", "s", "[", "1", "]", ".", "\"@\"", ".", "$", "s", "[", "2", "]", ",", "FILTER_VALIDATE_EMAIL", ")", "===", "false", ")", "{", "return", "false", ";", "}", "}", "return", "str_replace", "(", "array", "(", "'%n'", ",", "'%t'", ",", "'%d'", ",", "'%h'", ",", "'%z'", ",", "'%s'", ")", ",", "array", "(", "$", "n", ",", "$", "t", ",", "$", "d", ",", "$", "h", ",", "$", "z", ",", "$", "s", "[", "2", "]", ")", ",", "$", "name", ")", ";", "}" ]
Replaces hostname variables. @param string $name Hostname @param string $host Optional IMAP hostname @return string Hostname
[ "Replaces", "hostname", "variables", "." ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_utils.php#L561-L589
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_utils.php
rcube_utils.remote_ip
public static function remote_ip() { $address = $_SERVER['REMOTE_ADDR']; // append the NGINX X-Real-IP header, if set if (!empty($_SERVER['HTTP_X_REAL_IP'])) { $remote_ip[] = 'X-Real-IP: ' . $_SERVER['HTTP_X_REAL_IP']; } // append the X-Forwarded-For header, if set if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { $remote_ip[] = 'X-Forwarded-For: ' . $_SERVER['HTTP_X_FORWARDED_FOR']; } if (!empty($remote_ip)) { $address .= '(' . implode(',', $remote_ip) . ')'; } return $address; }
php
public static function remote_ip() { $address = $_SERVER['REMOTE_ADDR']; // append the NGINX X-Real-IP header, if set if (!empty($_SERVER['HTTP_X_REAL_IP'])) { $remote_ip[] = 'X-Real-IP: ' . $_SERVER['HTTP_X_REAL_IP']; } // append the X-Forwarded-For header, if set if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { $remote_ip[] = 'X-Forwarded-For: ' . $_SERVER['HTTP_X_FORWARDED_FOR']; } if (!empty($remote_ip)) { $address .= '(' . implode(',', $remote_ip) . ')'; } return $address; }
[ "public", "static", "function", "remote_ip", "(", ")", "{", "$", "address", "=", "$", "_SERVER", "[", "'REMOTE_ADDR'", "]", ";", "// append the NGINX X-Real-IP header, if set", "if", "(", "!", "empty", "(", "$", "_SERVER", "[", "'HTTP_X_REAL_IP'", "]", ")", ")", "{", "$", "remote_ip", "[", "]", "=", "'X-Real-IP: '", ".", "$", "_SERVER", "[", "'HTTP_X_REAL_IP'", "]", ";", "}", "// append the X-Forwarded-For header, if set", "if", "(", "!", "empty", "(", "$", "_SERVER", "[", "'HTTP_X_FORWARDED_FOR'", "]", ")", ")", "{", "$", "remote_ip", "[", "]", "=", "'X-Forwarded-For: '", ".", "$", "_SERVER", "[", "'HTTP_X_FORWARDED_FOR'", "]", ";", "}", "if", "(", "!", "empty", "(", "$", "remote_ip", ")", ")", "{", "$", "address", ".=", "'('", ".", "implode", "(", "','", ",", "$", "remote_ip", ")", ".", "')'", ";", "}", "return", "$", "address", ";", "}" ]
Returns remote IP address and forwarded addresses if found @return string Remote IP address(es)
[ "Returns", "remote", "IP", "address", "and", "forwarded", "addresses", "if", "found" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_utils.php#L596-L615
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_utils.php
rcube_utils.remote_addr
public static function remote_addr() { // Check if any of the headers are set first to improve performance if (!empty($_SERVER['HTTP_X_FORWARDED_FOR']) || !empty($_SERVER['HTTP_X_REAL_IP'])) { $proxy_whitelist = rcube::get_instance()->config->get('proxy_whitelist', array()); if (in_array($_SERVER['REMOTE_ADDR'], $proxy_whitelist)) { if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { foreach (array_reverse(explode(',', $_SERVER['HTTP_X_FORWARDED_FOR'])) as $forwarded_ip) { if (!in_array($forwarded_ip, $proxy_whitelist)) { return $forwarded_ip; } } } if (!empty($_SERVER['HTTP_X_REAL_IP'])) { return $_SERVER['HTTP_X_REAL_IP']; } } } if (!empty($_SERVER['REMOTE_ADDR'])) { return $_SERVER['REMOTE_ADDR']; } return ''; }
php
public static function remote_addr() { // Check if any of the headers are set first to improve performance if (!empty($_SERVER['HTTP_X_FORWARDED_FOR']) || !empty($_SERVER['HTTP_X_REAL_IP'])) { $proxy_whitelist = rcube::get_instance()->config->get('proxy_whitelist', array()); if (in_array($_SERVER['REMOTE_ADDR'], $proxy_whitelist)) { if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { foreach (array_reverse(explode(',', $_SERVER['HTTP_X_FORWARDED_FOR'])) as $forwarded_ip) { if (!in_array($forwarded_ip, $proxy_whitelist)) { return $forwarded_ip; } } } if (!empty($_SERVER['HTTP_X_REAL_IP'])) { return $_SERVER['HTTP_X_REAL_IP']; } } } if (!empty($_SERVER['REMOTE_ADDR'])) { return $_SERVER['REMOTE_ADDR']; } return ''; }
[ "public", "static", "function", "remote_addr", "(", ")", "{", "// Check if any of the headers are set first to improve performance", "if", "(", "!", "empty", "(", "$", "_SERVER", "[", "'HTTP_X_FORWARDED_FOR'", "]", ")", "||", "!", "empty", "(", "$", "_SERVER", "[", "'HTTP_X_REAL_IP'", "]", ")", ")", "{", "$", "proxy_whitelist", "=", "rcube", "::", "get_instance", "(", ")", "->", "config", "->", "get", "(", "'proxy_whitelist'", ",", "array", "(", ")", ")", ";", "if", "(", "in_array", "(", "$", "_SERVER", "[", "'REMOTE_ADDR'", "]", ",", "$", "proxy_whitelist", ")", ")", "{", "if", "(", "!", "empty", "(", "$", "_SERVER", "[", "'HTTP_X_FORWARDED_FOR'", "]", ")", ")", "{", "foreach", "(", "array_reverse", "(", "explode", "(", "','", ",", "$", "_SERVER", "[", "'HTTP_X_FORWARDED_FOR'", "]", ")", ")", "as", "$", "forwarded_ip", ")", "{", "if", "(", "!", "in_array", "(", "$", "forwarded_ip", ",", "$", "proxy_whitelist", ")", ")", "{", "return", "$", "forwarded_ip", ";", "}", "}", "}", "if", "(", "!", "empty", "(", "$", "_SERVER", "[", "'HTTP_X_REAL_IP'", "]", ")", ")", "{", "return", "$", "_SERVER", "[", "'HTTP_X_REAL_IP'", "]", ";", "}", "}", "}", "if", "(", "!", "empty", "(", "$", "_SERVER", "[", "'REMOTE_ADDR'", "]", ")", ")", "{", "return", "$", "_SERVER", "[", "'REMOTE_ADDR'", "]", ";", "}", "return", "''", ";", "}" ]
Returns the real remote IP address @return string Remote IP address
[ "Returns", "the", "real", "remote", "IP", "address" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_utils.php#L622-L647
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_utils.php
rcube_utils.request_header
public static function request_header($name) { if (function_exists('getallheaders')) { $hdrs = array_change_key_case(getallheaders(), CASE_UPPER); $key = strtoupper($name); } else { $key = 'HTTP_' . strtoupper(strtr($name, '-', '_')); $hdrs = array_change_key_case($_SERVER, CASE_UPPER); } return $hdrs[$key]; }
php
public static function request_header($name) { if (function_exists('getallheaders')) { $hdrs = array_change_key_case(getallheaders(), CASE_UPPER); $key = strtoupper($name); } else { $key = 'HTTP_' . strtoupper(strtr($name, '-', '_')); $hdrs = array_change_key_case($_SERVER, CASE_UPPER); } return $hdrs[$key]; }
[ "public", "static", "function", "request_header", "(", "$", "name", ")", "{", "if", "(", "function_exists", "(", "'getallheaders'", ")", ")", "{", "$", "hdrs", "=", "array_change_key_case", "(", "getallheaders", "(", ")", ",", "CASE_UPPER", ")", ";", "$", "key", "=", "strtoupper", "(", "$", "name", ")", ";", "}", "else", "{", "$", "key", "=", "'HTTP_'", ".", "strtoupper", "(", "strtr", "(", "$", "name", ",", "'-'", ",", "'_'", ")", ")", ";", "$", "hdrs", "=", "array_change_key_case", "(", "$", "_SERVER", ",", "CASE_UPPER", ")", ";", "}", "return", "$", "hdrs", "[", "$", "key", "]", ";", "}" ]
Read a specific HTTP request header. @param string $name Header name @return mixed Header value or null if not available
[ "Read", "a", "specific", "HTTP", "request", "header", "." ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_utils.php#L656-L668
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_utils.php
rcube_utils.explode_quoted_string
public static function explode_quoted_string($delimiter, $string) { $result = array(); $strlen = strlen($string); for ($q=$p=$i=0; $i < $strlen; $i++) { if ($string[$i] == "\"" && $string[$i-1] != "\\") { $q = $q ? false : true; } else if (!$q && preg_match("/$delimiter/", $string[$i])) { $result[] = substr($string, $p, $i - $p); $p = $i + 1; } } $result[] = (string) substr($string, $p); return $result; }
php
public static function explode_quoted_string($delimiter, $string) { $result = array(); $strlen = strlen($string); for ($q=$p=$i=0; $i < $strlen; $i++) { if ($string[$i] == "\"" && $string[$i-1] != "\\") { $q = $q ? false : true; } else if (!$q && preg_match("/$delimiter/", $string[$i])) { $result[] = substr($string, $p, $i - $p); $p = $i + 1; } } $result[] = (string) substr($string, $p); return $result; }
[ "public", "static", "function", "explode_quoted_string", "(", "$", "delimiter", ",", "$", "string", ")", "{", "$", "result", "=", "array", "(", ")", ";", "$", "strlen", "=", "strlen", "(", "$", "string", ")", ";", "for", "(", "$", "q", "=", "$", "p", "=", "$", "i", "=", "0", ";", "$", "i", "<", "$", "strlen", ";", "$", "i", "++", ")", "{", "if", "(", "$", "string", "[", "$", "i", "]", "==", "\"\\\"\"", "&&", "$", "string", "[", "$", "i", "-", "1", "]", "!=", "\"\\\\\"", ")", "{", "$", "q", "=", "$", "q", "?", "false", ":", "true", ";", "}", "else", "if", "(", "!", "$", "q", "&&", "preg_match", "(", "\"/$delimiter/\"", ",", "$", "string", "[", "$", "i", "]", ")", ")", "{", "$", "result", "[", "]", "=", "substr", "(", "$", "string", ",", "$", "p", ",", "$", "i", "-", "$", "p", ")", ";", "$", "p", "=", "$", "i", "+", "1", ";", "}", "}", "$", "result", "[", "]", "=", "(", "string", ")", "substr", "(", "$", "string", ",", "$", "p", ")", ";", "return", "$", "result", ";", "}" ]
Explode quoted string @param string Delimiter expression string for preg_match() @param string Input string @return array String items
[ "Explode", "quoted", "string" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_utils.php#L678-L696
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_utils.php
rcube_utils.anytodatetime
public static function anytodatetime($date, $timezone = null) { if ($date instanceof DateTime) { return $date; } $dt = false; $date = self::clean_datestr($date); // try to parse string with DateTime first if (!empty($date)) { try { $_date = preg_match('/^[0-9]+$/', $date) ? "@$date" : $date; $dt = $timezone ? new DateTime($_date, $timezone) : new DateTime($_date); } catch (Exception $e) { // ignore } } // try our advanced strtotime() method if (!$dt && ($timestamp = self::strtotime($date, $timezone))) { try { $dt = new DateTime("@".$timestamp); if ($timezone) { $dt->setTimezone($timezone); } } catch (Exception $e) { // ignore } } return $dt; }
php
public static function anytodatetime($date, $timezone = null) { if ($date instanceof DateTime) { return $date; } $dt = false; $date = self::clean_datestr($date); // try to parse string with DateTime first if (!empty($date)) { try { $_date = preg_match('/^[0-9]+$/', $date) ? "@$date" : $date; $dt = $timezone ? new DateTime($_date, $timezone) : new DateTime($_date); } catch (Exception $e) { // ignore } } // try our advanced strtotime() method if (!$dt && ($timestamp = self::strtotime($date, $timezone))) { try { $dt = new DateTime("@".$timestamp); if ($timezone) { $dt->setTimezone($timezone); } } catch (Exception $e) { // ignore } } return $dt; }
[ "public", "static", "function", "anytodatetime", "(", "$", "date", ",", "$", "timezone", "=", "null", ")", "{", "if", "(", "$", "date", "instanceof", "DateTime", ")", "{", "return", "$", "date", ";", "}", "$", "dt", "=", "false", ";", "$", "date", "=", "self", "::", "clean_datestr", "(", "$", "date", ")", ";", "// try to parse string with DateTime first", "if", "(", "!", "empty", "(", "$", "date", ")", ")", "{", "try", "{", "$", "_date", "=", "preg_match", "(", "'/^[0-9]+$/'", ",", "$", "date", ")", "?", "\"@$date\"", ":", "$", "date", ";", "$", "dt", "=", "$", "timezone", "?", "new", "DateTime", "(", "$", "_date", ",", "$", "timezone", ")", ":", "new", "DateTime", "(", "$", "_date", ")", ";", "}", "catch", "(", "Exception", "$", "e", ")", "{", "// ignore", "}", "}", "// try our advanced strtotime() method", "if", "(", "!", "$", "dt", "&&", "(", "$", "timestamp", "=", "self", "::", "strtotime", "(", "$", "date", ",", "$", "timezone", ")", ")", ")", "{", "try", "{", "$", "dt", "=", "new", "DateTime", "(", "\"@\"", ".", "$", "timestamp", ")", ";", "if", "(", "$", "timezone", ")", "{", "$", "dt", "->", "setTimezone", "(", "$", "timezone", ")", ";", "}", "}", "catch", "(", "Exception", "$", "e", ")", "{", "// ignore", "}", "}", "return", "$", "dt", ";", "}" ]
Date parsing function that turns the given value into a DateTime object @param string $date Date string @param DateTimeZone $timezone Timezone to use for DateTime object @return DateTime instance or false on failure
[ "Date", "parsing", "function", "that", "turns", "the", "given", "value", "into", "a", "DateTime", "object" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_utils.php#L742-L776
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_utils.php
rcube_utils.tokenize_string
public static function tokenize_string($str, $minlen = 2) { $expr = array('/[\s;,"\'\/+-]+/ui', '/(\d)[-.\s]+(\d)/u'); $repl = array(' ', '\\1\\2'); if ($minlen > 1) { $minlen--; $expr[] = "/(^|\s+)\w{1,$minlen}(\s+|$)/u"; $repl[] = ' '; } return array_filter(explode(" ", preg_replace($expr, $repl, $str))); }
php
public static function tokenize_string($str, $minlen = 2) { $expr = array('/[\s;,"\'\/+-]+/ui', '/(\d)[-.\s]+(\d)/u'); $repl = array(' ', '\\1\\2'); if ($minlen > 1) { $minlen--; $expr[] = "/(^|\s+)\w{1,$minlen}(\s+|$)/u"; $repl[] = ' '; } return array_filter(explode(" ", preg_replace($expr, $repl, $str))); }
[ "public", "static", "function", "tokenize_string", "(", "$", "str", ",", "$", "minlen", "=", "2", ")", "{", "$", "expr", "=", "array", "(", "'/[\\s;,\"\\'\\/+-]+/ui'", ",", "'/(\\d)[-.\\s]+(\\d)/u'", ")", ";", "$", "repl", "=", "array", "(", "' '", ",", "'\\\\1\\\\2'", ")", ";", "if", "(", "$", "minlen", ">", "1", ")", "{", "$", "minlen", "--", ";", "$", "expr", "[", "]", "=", "\"/(^|\\s+)\\w{1,$minlen}(\\s+|$)/u\"", ";", "$", "repl", "[", "]", "=", "' '", ";", "}", "return", "array_filter", "(", "explode", "(", "\" \"", ",", "preg_replace", "(", "$", "expr", ",", "$", "repl", ",", "$", "str", ")", ")", ")", ";", "}" ]
Split the given string into word tokens @param string Input to tokenize @param integer Minimum length of a single token @return array List of tokens
[ "Split", "the", "given", "string", "into", "word", "tokens" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_utils.php#L936-L948
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_utils.php
rcube_utils.get_opt
public static function get_opt($aliases = array()) { $args = array(); $bool = array(); // find boolean (no value) options foreach ($aliases as $key => $alias) { if ($pos = strpos($alias, ':')) { $aliases[$key] = substr($alias, 0, $pos); $bool[] = $key; $bool[] = $aliases[$key]; } } for ($i=1; $i < count($_SERVER['argv']); $i++) { $arg = $_SERVER['argv'][$i]; $value = true; $key = null; if ($arg[0] == '-') { $key = preg_replace('/^-+/', '', $arg); $sp = strpos($arg, '='); if ($sp > 0) { $key = substr($key, 0, $sp - 2); $value = substr($arg, $sp+1); } else if (in_array($key, $bool)) { $value = true; } else if (strlen($_SERVER['argv'][$i+1]) && $_SERVER['argv'][$i+1][0] != '-') { $value = $_SERVER['argv'][++$i]; } $args[$key] = is_string($value) ? preg_replace(array('/^["\']/', '/["\']$/'), '', $value) : $value; } else { $args[] = $arg; } if ($alias = $aliases[$key]) { $args[$alias] = $args[$key]; } } return $args; }
php
public static function get_opt($aliases = array()) { $args = array(); $bool = array(); // find boolean (no value) options foreach ($aliases as $key => $alias) { if ($pos = strpos($alias, ':')) { $aliases[$key] = substr($alias, 0, $pos); $bool[] = $key; $bool[] = $aliases[$key]; } } for ($i=1; $i < count($_SERVER['argv']); $i++) { $arg = $_SERVER['argv'][$i]; $value = true; $key = null; if ($arg[0] == '-') { $key = preg_replace('/^-+/', '', $arg); $sp = strpos($arg, '='); if ($sp > 0) { $key = substr($key, 0, $sp - 2); $value = substr($arg, $sp+1); } else if (in_array($key, $bool)) { $value = true; } else if (strlen($_SERVER['argv'][$i+1]) && $_SERVER['argv'][$i+1][0] != '-') { $value = $_SERVER['argv'][++$i]; } $args[$key] = is_string($value) ? preg_replace(array('/^["\']/', '/["\']$/'), '', $value) : $value; } else { $args[] = $arg; } if ($alias = $aliases[$key]) { $args[$alias] = $args[$key]; } } return $args; }
[ "public", "static", "function", "get_opt", "(", "$", "aliases", "=", "array", "(", ")", ")", "{", "$", "args", "=", "array", "(", ")", ";", "$", "bool", "=", "array", "(", ")", ";", "// find boolean (no value) options", "foreach", "(", "$", "aliases", "as", "$", "key", "=>", "$", "alias", ")", "{", "if", "(", "$", "pos", "=", "strpos", "(", "$", "alias", ",", "':'", ")", ")", "{", "$", "aliases", "[", "$", "key", "]", "=", "substr", "(", "$", "alias", ",", "0", ",", "$", "pos", ")", ";", "$", "bool", "[", "]", "=", "$", "key", ";", "$", "bool", "[", "]", "=", "$", "aliases", "[", "$", "key", "]", ";", "}", "}", "for", "(", "$", "i", "=", "1", ";", "$", "i", "<", "count", "(", "$", "_SERVER", "[", "'argv'", "]", ")", ";", "$", "i", "++", ")", "{", "$", "arg", "=", "$", "_SERVER", "[", "'argv'", "]", "[", "$", "i", "]", ";", "$", "value", "=", "true", ";", "$", "key", "=", "null", ";", "if", "(", "$", "arg", "[", "0", "]", "==", "'-'", ")", "{", "$", "key", "=", "preg_replace", "(", "'/^-+/'", ",", "''", ",", "$", "arg", ")", ";", "$", "sp", "=", "strpos", "(", "$", "arg", ",", "'='", ")", ";", "if", "(", "$", "sp", ">", "0", ")", "{", "$", "key", "=", "substr", "(", "$", "key", ",", "0", ",", "$", "sp", "-", "2", ")", ";", "$", "value", "=", "substr", "(", "$", "arg", ",", "$", "sp", "+", "1", ")", ";", "}", "else", "if", "(", "in_array", "(", "$", "key", ",", "$", "bool", ")", ")", "{", "$", "value", "=", "true", ";", "}", "else", "if", "(", "strlen", "(", "$", "_SERVER", "[", "'argv'", "]", "[", "$", "i", "+", "1", "]", ")", "&&", "$", "_SERVER", "[", "'argv'", "]", "[", "$", "i", "+", "1", "]", "[", "0", "]", "!=", "'-'", ")", "{", "$", "value", "=", "$", "_SERVER", "[", "'argv'", "]", "[", "++", "$", "i", "]", ";", "}", "$", "args", "[", "$", "key", "]", "=", "is_string", "(", "$", "value", ")", "?", "preg_replace", "(", "array", "(", "'/^[\"\\']/'", ",", "'/[\"\\']$/'", ")", ",", "''", ",", "$", "value", ")", ":", "$", "value", ";", "}", "else", "{", "$", "args", "[", "]", "=", "$", "arg", ";", "}", "if", "(", "$", "alias", "=", "$", "aliases", "[", "$", "key", "]", ")", "{", "$", "args", "[", "$", "alias", "]", "=", "$", "args", "[", "$", "key", "]", ";", "}", "}", "return", "$", "args", ";", "}" ]
Parse commandline arguments into a hash array @param array $aliases Argument alias names @return array Argument values hash
[ "Parse", "commandline", "arguments", "into", "a", "hash", "array" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_utils.php#L1041-L1087
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_utils.php
rcube_utils.resolve_url
public static function resolve_url($url) { // prepend protocol://hostname:port if (!preg_match('|^https?://|', $url)) { $schema = 'http'; $default_port = 80; if (self::https_check()) { $schema = 'https'; $default_port = 443; } $prefix = $schema . '://' . preg_replace('/:\d+$/', '', $_SERVER['HTTP_HOST']); if ($_SERVER['SERVER_PORT'] != $default_port) { $prefix .= ':' . $_SERVER['SERVER_PORT']; } $url = $prefix . ($url[0] == '/' ? '' : '/') . $url; } return $url; }
php
public static function resolve_url($url) { // prepend protocol://hostname:port if (!preg_match('|^https?://|', $url)) { $schema = 'http'; $default_port = 80; if (self::https_check()) { $schema = 'https'; $default_port = 443; } $prefix = $schema . '://' . preg_replace('/:\d+$/', '', $_SERVER['HTTP_HOST']); if ($_SERVER['SERVER_PORT'] != $default_port) { $prefix .= ':' . $_SERVER['SERVER_PORT']; } $url = $prefix . ($url[0] == '/' ? '' : '/') . $url; } return $url; }
[ "public", "static", "function", "resolve_url", "(", "$", "url", ")", "{", "// prepend protocol://hostname:port", "if", "(", "!", "preg_match", "(", "'|^https?://|'", ",", "$", "url", ")", ")", "{", "$", "schema", "=", "'http'", ";", "$", "default_port", "=", "80", ";", "if", "(", "self", "::", "https_check", "(", ")", ")", "{", "$", "schema", "=", "'https'", ";", "$", "default_port", "=", "443", ";", "}", "$", "prefix", "=", "$", "schema", ".", "'://'", ".", "preg_replace", "(", "'/:\\d+$/'", ",", "''", ",", "$", "_SERVER", "[", "'HTTP_HOST'", "]", ")", ";", "if", "(", "$", "_SERVER", "[", "'SERVER_PORT'", "]", "!=", "$", "default_port", ")", "{", "$", "prefix", ".=", "':'", ".", "$", "_SERVER", "[", "'SERVER_PORT'", "]", ";", "}", "$", "url", "=", "$", "prefix", ".", "(", "$", "url", "[", "0", "]", "==", "'/'", "?", "''", ":", "'/'", ")", ".", "$", "url", ";", "}", "return", "$", "url", ";", "}" ]
Resolve relative URL @param string $url Relative URL @return string Absolute URL
[ "Resolve", "relative", "URL" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_utils.php#L1158-L1179
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_utils.php
rcube_utils.parse_socket_options
public static function parse_socket_options(&$options, $host = null) { if (empty($host) || empty($options)) { return $options; } // get rid of schema and port from the hostname $host_url = parse_url($host); if (isset($host_url['host'])) { $host = $host_url['host']; } // find per-host options if (array_key_exists($host, $options)) { $options = $options[$host]; } }
php
public static function parse_socket_options(&$options, $host = null) { if (empty($host) || empty($options)) { return $options; } // get rid of schema and port from the hostname $host_url = parse_url($host); if (isset($host_url['host'])) { $host = $host_url['host']; } // find per-host options if (array_key_exists($host, $options)) { $options = $options[$host]; } }
[ "public", "static", "function", "parse_socket_options", "(", "&", "$", "options", ",", "$", "host", "=", "null", ")", "{", "if", "(", "empty", "(", "$", "host", ")", "||", "empty", "(", "$", "options", ")", ")", "{", "return", "$", "options", ";", "}", "// get rid of schema and port from the hostname", "$", "host_url", "=", "parse_url", "(", "$", "host", ")", ";", "if", "(", "isset", "(", "$", "host_url", "[", "'host'", "]", ")", ")", "{", "$", "host", "=", "$", "host_url", "[", "'host'", "]", ";", "}", "// find per-host options", "if", "(", "array_key_exists", "(", "$", "host", ",", "$", "options", ")", ")", "{", "$", "options", "=", "$", "options", "[", "$", "host", "]", ";", "}", "}" ]
Parses socket options and returns options for specified hostname. @param array &$options Configured socket options @param string $host Hostname
[ "Parses", "socket", "options", "and", "returns", "options", "for", "specified", "hostname", "." ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_utils.php#L1275-L1291
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_utils.php
rcube_utils.max_upload_size
public static function max_upload_size() { // find max filesize value $max_filesize = parse_bytes(ini_get('upload_max_filesize')); $max_postsize = parse_bytes(ini_get('post_max_size')); if ($max_postsize && $max_postsize < $max_filesize) { $max_filesize = $max_postsize; } return $max_filesize; }
php
public static function max_upload_size() { // find max filesize value $max_filesize = parse_bytes(ini_get('upload_max_filesize')); $max_postsize = parse_bytes(ini_get('post_max_size')); if ($max_postsize && $max_postsize < $max_filesize) { $max_filesize = $max_postsize; } return $max_filesize; }
[ "public", "static", "function", "max_upload_size", "(", ")", "{", "// find max filesize value", "$", "max_filesize", "=", "parse_bytes", "(", "ini_get", "(", "'upload_max_filesize'", ")", ")", ";", "$", "max_postsize", "=", "parse_bytes", "(", "ini_get", "(", "'post_max_size'", ")", ")", ";", "if", "(", "$", "max_postsize", "&&", "$", "max_postsize", "<", "$", "max_filesize", ")", "{", "$", "max_filesize", "=", "$", "max_postsize", ";", "}", "return", "$", "max_filesize", ";", "}" ]
Get maximum upload size @return int Maximum size in bytes
[ "Get", "maximum", "upload", "size" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_utils.php#L1298-L1309
train
i-MSCP/roundcube
roundcubemail/plugins/enigma/lib/enigma_mime_message.php
enigma_mime_message.getFromAddress
public function getFromAddress() { // get sender address $headers = $this->message->headers(); $from = rcube_mime::decode_address_list($headers['From'], 1, false, null, true); $from = $from[1]; return $from; }
php
public function getFromAddress() { // get sender address $headers = $this->message->headers(); $from = rcube_mime::decode_address_list($headers['From'], 1, false, null, true); $from = $from[1]; return $from; }
[ "public", "function", "getFromAddress", "(", ")", "{", "// get sender address", "$", "headers", "=", "$", "this", "->", "message", "->", "headers", "(", ")", ";", "$", "from", "=", "rcube_mime", "::", "decode_address_list", "(", "$", "headers", "[", "'From'", "]", ",", "1", ",", "false", ",", "null", ",", "true", ")", ";", "$", "from", "=", "$", "from", "[", "1", "]", ";", "return", "$", "from", ";", "}" ]
Get e-mail address of message sender @return string Sender address
[ "Get", "e", "-", "mail", "address", "of", "message", "sender" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/plugins/enigma/lib/enigma_mime_message.php#L70-L78
train
i-MSCP/roundcube
roundcubemail/plugins/enigma/lib/enigma_mime_message.php
enigma_mime_message.getRecipients
public function getRecipients() { // get sender address $headers = $this->message->headers(); $to = rcube_mime::decode_address_list($headers['To'], null, false, null, true); $cc = rcube_mime::decode_address_list($headers['Cc'], null, false, null, true); $bcc = rcube_mime::decode_address_list($headers['Bcc'], null, false, null, true); $recipients = array_unique(array_merge($to, $cc, $bcc)); $recipients = array_diff($recipients, array('undisclosed-recipients:')); return $recipients; }
php
public function getRecipients() { // get sender address $headers = $this->message->headers(); $to = rcube_mime::decode_address_list($headers['To'], null, false, null, true); $cc = rcube_mime::decode_address_list($headers['Cc'], null, false, null, true); $bcc = rcube_mime::decode_address_list($headers['Bcc'], null, false, null, true); $recipients = array_unique(array_merge($to, $cc, $bcc)); $recipients = array_diff($recipients, array('undisclosed-recipients:')); return $recipients; }
[ "public", "function", "getRecipients", "(", ")", "{", "// get sender address", "$", "headers", "=", "$", "this", "->", "message", "->", "headers", "(", ")", ";", "$", "to", "=", "rcube_mime", "::", "decode_address_list", "(", "$", "headers", "[", "'To'", "]", ",", "null", ",", "false", ",", "null", ",", "true", ")", ";", "$", "cc", "=", "rcube_mime", "::", "decode_address_list", "(", "$", "headers", "[", "'Cc'", "]", ",", "null", ",", "false", ",", "null", ",", "true", ")", ";", "$", "bcc", "=", "rcube_mime", "::", "decode_address_list", "(", "$", "headers", "[", "'Bcc'", "]", ",", "null", ",", "false", ",", "null", ",", "true", ")", ";", "$", "recipients", "=", "array_unique", "(", "array_merge", "(", "$", "to", ",", "$", "cc", ",", "$", "bcc", ")", ")", ";", "$", "recipients", "=", "array_diff", "(", "$", "recipients", ",", "array", "(", "'undisclosed-recipients:'", ")", ")", ";", "return", "$", "recipients", ";", "}" ]
Get recipients' e-mail addresses @return array Recipients' addresses
[ "Get", "recipients", "e", "-", "mail", "addresses" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/plugins/enigma/lib/enigma_mime_message.php#L85-L97
train
i-MSCP/roundcube
roundcubemail/plugins/enigma/lib/enigma_mime_message.php
enigma_mime_message.addPGPSignature
public function addPGPSignature($body, $algorithm = null) { $this->signature = $body; $this->micalg = $algorithm; // Reset Content-Type to be overwritten with valid boundary unset($this->headers['Content-Type']); unset($this->headers['Content-Transfer-Encoding']); }
php
public function addPGPSignature($body, $algorithm = null) { $this->signature = $body; $this->micalg = $algorithm; // Reset Content-Type to be overwritten with valid boundary unset($this->headers['Content-Type']); unset($this->headers['Content-Transfer-Encoding']); }
[ "public", "function", "addPGPSignature", "(", "$", "body", ",", "$", "algorithm", "=", "null", ")", "{", "$", "this", "->", "signature", "=", "$", "body", ";", "$", "this", "->", "micalg", "=", "$", "algorithm", ";", "// Reset Content-Type to be overwritten with valid boundary", "unset", "(", "$", "this", "->", "headers", "[", "'Content-Type'", "]", ")", ";", "unset", "(", "$", "this", "->", "headers", "[", "'Content-Transfer-Encoding'", "]", ")", ";", "}" ]
Register signature attachment @param string Signature body @param string Hash algorithm name
[ "Register", "signature", "attachment" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/plugins/enigma/lib/enigma_mime_message.php#L125-L133
train
i-MSCP/roundcube
roundcubemail/plugins/enigma/lib/enigma_mime_message.php
enigma_mime_message.contentHeaders
protected function contentHeaders() { $this->checkParams(); $eol = $this->build_params['eol'] ?: "\r\n"; // multipart message: and boundary if (!empty($this->build_params['boundary'])) { $boundary = $this->build_params['boundary']; } else if (!empty($this->headers['Content-Type']) && preg_match('/boundary="([^"]+)"/', $this->headers['Content-Type'], $m) ) { $boundary = $m[1]; } else { $boundary = '=_' . md5(rand() . microtime()); } $this->build_params['boundary'] = $boundary; if ($this->type == self::PGP_SIGNED) { $headers['Content-Type'] = "multipart/signed;$eol" ." protocol=\"application/pgp-signature\";$eol" ." boundary=\"$boundary\""; if ($this->micalg) { $headers['Content-Type'] .= ";{$eol} micalg=pgp-" . $this->micalg; } } else if ($this->type == self::PGP_ENCRYPTED) { $headers['Content-Type'] = "multipart/encrypted;$eol" ." protocol=\"application/pgp-encrypted\";$eol" ." boundary=\"$boundary\""; } return $headers; }
php
protected function contentHeaders() { $this->checkParams(); $eol = $this->build_params['eol'] ?: "\r\n"; // multipart message: and boundary if (!empty($this->build_params['boundary'])) { $boundary = $this->build_params['boundary']; } else if (!empty($this->headers['Content-Type']) && preg_match('/boundary="([^"]+)"/', $this->headers['Content-Type'], $m) ) { $boundary = $m[1]; } else { $boundary = '=_' . md5(rand() . microtime()); } $this->build_params['boundary'] = $boundary; if ($this->type == self::PGP_SIGNED) { $headers['Content-Type'] = "multipart/signed;$eol" ." protocol=\"application/pgp-signature\";$eol" ." boundary=\"$boundary\""; if ($this->micalg) { $headers['Content-Type'] .= ";{$eol} micalg=pgp-" . $this->micalg; } } else if ($this->type == self::PGP_ENCRYPTED) { $headers['Content-Type'] = "multipart/encrypted;$eol" ." protocol=\"application/pgp-encrypted\";$eol" ." boundary=\"$boundary\""; } return $headers; }
[ "protected", "function", "contentHeaders", "(", ")", "{", "$", "this", "->", "checkParams", "(", ")", ";", "$", "eol", "=", "$", "this", "->", "build_params", "[", "'eol'", "]", "?", ":", "\"\\r\\n\"", ";", "// multipart message: and boundary", "if", "(", "!", "empty", "(", "$", "this", "->", "build_params", "[", "'boundary'", "]", ")", ")", "{", "$", "boundary", "=", "$", "this", "->", "build_params", "[", "'boundary'", "]", ";", "}", "else", "if", "(", "!", "empty", "(", "$", "this", "->", "headers", "[", "'Content-Type'", "]", ")", "&&", "preg_match", "(", "'/boundary=\"([^\"]+)\"/'", ",", "$", "this", "->", "headers", "[", "'Content-Type'", "]", ",", "$", "m", ")", ")", "{", "$", "boundary", "=", "$", "m", "[", "1", "]", ";", "}", "else", "{", "$", "boundary", "=", "'=_'", ".", "md5", "(", "rand", "(", ")", ".", "microtime", "(", ")", ")", ";", "}", "$", "this", "->", "build_params", "[", "'boundary'", "]", "=", "$", "boundary", ";", "if", "(", "$", "this", "->", "type", "==", "self", "::", "PGP_SIGNED", ")", "{", "$", "headers", "[", "'Content-Type'", "]", "=", "\"multipart/signed;$eol\"", ".", "\" protocol=\\\"application/pgp-signature\\\";$eol\"", ".", "\" boundary=\\\"$boundary\\\"\"", ";", "if", "(", "$", "this", "->", "micalg", ")", "{", "$", "headers", "[", "'Content-Type'", "]", ".=", "\";{$eol} micalg=pgp-\"", ".", "$", "this", "->", "micalg", ";", "}", "}", "else", "if", "(", "$", "this", "->", "type", "==", "self", "::", "PGP_ENCRYPTED", ")", "{", "$", "headers", "[", "'Content-Type'", "]", "=", "\"multipart/encrypted;$eol\"", ".", "\" protocol=\\\"application/pgp-encrypted\\\";$eol\"", ".", "\" boundary=\\\"$boundary\\\"\"", ";", "}", "return", "$", "headers", ";", "}" ]
Get Content-Type and Content-Transfer-Encoding headers of the message @return array Headers array
[ "Get", "Content", "-", "Type", "and", "Content", "-", "Transfer", "-", "Encoding", "headers", "of", "the", "message" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/plugins/enigma/lib/enigma_mime_message.php#L267-L304
train
i-MSCP/roundcube
roundcubemail/plugins/new_user_dialog/new_user_dialog.php
new_user_dialog.render_page
function render_page($p) { if ($_SESSION['plugin.newuserdialog']) { $this->add_texts('localization'); $rcmail = rcmail::get_instance(); $identity = $rcmail->user->get_identity(); $identities_level = intval($rcmail->config->get('identities_level', 0)); // compose user-identity dialog $table = new html_table(array('cols' => 2)); $table->add('title', $this->gettext('name')); $table->add(null, html::tag('input', array( 'type' => 'text', 'name' => '_name', 'value' => $identity['name'], 'disabled' => $identities_level == 4 ))); $table->add('title', $this->gettext('email')); $table->add(null, html::tag('input', array( 'type' => 'text', 'name' => '_email', 'value' => rcube_utils::idn_to_utf8($identity['email']), 'disabled' => in_array($identities_level, array(1, 3, 4)) ))); $table->add('title', $this->gettext('organization')); $table->add(null, html::tag('input', array( 'type' => 'text', 'name' => '_organization', 'value' => $identity['organization'], 'disabled' => $identities_level == 4 ))); $table->add('title', $this->gettext('signature')); $table->add(null, html::tag('textarea', array( 'name' => '_signature', 'rows' => '3', ), $identity['signature'] )); // add overlay input box to html page $rcmail->output->add_footer(html::tag('form', array( 'id' => 'newuserdialog', 'action' => $rcmail->url('plugin.newusersave'), 'method' => 'post' ), html::p('hint', rcube::Q($this->gettext('identitydialoghint'))) . $table->show() . html::p(array('class' => 'formbuttons'), html::tag('input', array('type' => 'submit', 'class' => 'button mainaction', 'value' => $this->gettext('save')))) )); $title = rcube::JQ($this->gettext('identitydialogtitle')); $script = " $('#newuserdialog').show() .dialog({modal:true, resizable:false, closeOnEscape:false, width:450, title:'$title'}) .submit(function() { var i, request = {}, form = $(this).serializeArray(); for (i in form) request[form[i].name] = form[i].value; rcmail.http_post('plugin.newusersave', request, true); return false; }); $('input[name=_name]').focus(); rcube_webmail.prototype.new_user_dialog_close = function() { $('#newuserdialog').dialog('close'); } "; // disable keyboard events for messages list (#1486726) $rcmail->output->add_script($script, 'docready'); $this->include_stylesheet('newuserdialog.css'); } }
php
function render_page($p) { if ($_SESSION['plugin.newuserdialog']) { $this->add_texts('localization'); $rcmail = rcmail::get_instance(); $identity = $rcmail->user->get_identity(); $identities_level = intval($rcmail->config->get('identities_level', 0)); // compose user-identity dialog $table = new html_table(array('cols' => 2)); $table->add('title', $this->gettext('name')); $table->add(null, html::tag('input', array( 'type' => 'text', 'name' => '_name', 'value' => $identity['name'], 'disabled' => $identities_level == 4 ))); $table->add('title', $this->gettext('email')); $table->add(null, html::tag('input', array( 'type' => 'text', 'name' => '_email', 'value' => rcube_utils::idn_to_utf8($identity['email']), 'disabled' => in_array($identities_level, array(1, 3, 4)) ))); $table->add('title', $this->gettext('organization')); $table->add(null, html::tag('input', array( 'type' => 'text', 'name' => '_organization', 'value' => $identity['organization'], 'disabled' => $identities_level == 4 ))); $table->add('title', $this->gettext('signature')); $table->add(null, html::tag('textarea', array( 'name' => '_signature', 'rows' => '3', ), $identity['signature'] )); // add overlay input box to html page $rcmail->output->add_footer(html::tag('form', array( 'id' => 'newuserdialog', 'action' => $rcmail->url('plugin.newusersave'), 'method' => 'post' ), html::p('hint', rcube::Q($this->gettext('identitydialoghint'))) . $table->show() . html::p(array('class' => 'formbuttons'), html::tag('input', array('type' => 'submit', 'class' => 'button mainaction', 'value' => $this->gettext('save')))) )); $title = rcube::JQ($this->gettext('identitydialogtitle')); $script = " $('#newuserdialog').show() .dialog({modal:true, resizable:false, closeOnEscape:false, width:450, title:'$title'}) .submit(function() { var i, request = {}, form = $(this).serializeArray(); for (i in form) request[form[i].name] = form[i].value; rcmail.http_post('plugin.newusersave', request, true); return false; }); $('input[name=_name]').focus(); rcube_webmail.prototype.new_user_dialog_close = function() { $('#newuserdialog').dialog('close'); } "; // disable keyboard events for messages list (#1486726) $rcmail->output->add_script($script, 'docready'); $this->include_stylesheet('newuserdialog.css'); } }
[ "function", "render_page", "(", "$", "p", ")", "{", "if", "(", "$", "_SESSION", "[", "'plugin.newuserdialog'", "]", ")", "{", "$", "this", "->", "add_texts", "(", "'localization'", ")", ";", "$", "rcmail", "=", "rcmail", "::", "get_instance", "(", ")", ";", "$", "identity", "=", "$", "rcmail", "->", "user", "->", "get_identity", "(", ")", ";", "$", "identities_level", "=", "intval", "(", "$", "rcmail", "->", "config", "->", "get", "(", "'identities_level'", ",", "0", ")", ")", ";", "// compose user-identity dialog", "$", "table", "=", "new", "html_table", "(", "array", "(", "'cols'", "=>", "2", ")", ")", ";", "$", "table", "->", "add", "(", "'title'", ",", "$", "this", "->", "gettext", "(", "'name'", ")", ")", ";", "$", "table", "->", "add", "(", "null", ",", "html", "::", "tag", "(", "'input'", ",", "array", "(", "'type'", "=>", "'text'", ",", "'name'", "=>", "'_name'", ",", "'value'", "=>", "$", "identity", "[", "'name'", "]", ",", "'disabled'", "=>", "$", "identities_level", "==", "4", ")", ")", ")", ";", "$", "table", "->", "add", "(", "'title'", ",", "$", "this", "->", "gettext", "(", "'email'", ")", ")", ";", "$", "table", "->", "add", "(", "null", ",", "html", "::", "tag", "(", "'input'", ",", "array", "(", "'type'", "=>", "'text'", ",", "'name'", "=>", "'_email'", ",", "'value'", "=>", "rcube_utils", "::", "idn_to_utf8", "(", "$", "identity", "[", "'email'", "]", ")", ",", "'disabled'", "=>", "in_array", "(", "$", "identities_level", ",", "array", "(", "1", ",", "3", ",", "4", ")", ")", ")", ")", ")", ";", "$", "table", "->", "add", "(", "'title'", ",", "$", "this", "->", "gettext", "(", "'organization'", ")", ")", ";", "$", "table", "->", "add", "(", "null", ",", "html", "::", "tag", "(", "'input'", ",", "array", "(", "'type'", "=>", "'text'", ",", "'name'", "=>", "'_organization'", ",", "'value'", "=>", "$", "identity", "[", "'organization'", "]", ",", "'disabled'", "=>", "$", "identities_level", "==", "4", ")", ")", ")", ";", "$", "table", "->", "add", "(", "'title'", ",", "$", "this", "->", "gettext", "(", "'signature'", ")", ")", ";", "$", "table", "->", "add", "(", "null", ",", "html", "::", "tag", "(", "'textarea'", ",", "array", "(", "'name'", "=>", "'_signature'", ",", "'rows'", "=>", "'3'", ",", ")", ",", "$", "identity", "[", "'signature'", "]", ")", ")", ";", "// add overlay input box to html page", "$", "rcmail", "->", "output", "->", "add_footer", "(", "html", "::", "tag", "(", "'form'", ",", "array", "(", "'id'", "=>", "'newuserdialog'", ",", "'action'", "=>", "$", "rcmail", "->", "url", "(", "'plugin.newusersave'", ")", ",", "'method'", "=>", "'post'", ")", ",", "html", "::", "p", "(", "'hint'", ",", "rcube", "::", "Q", "(", "$", "this", "->", "gettext", "(", "'identitydialoghint'", ")", ")", ")", ".", "$", "table", "->", "show", "(", ")", ".", "html", "::", "p", "(", "array", "(", "'class'", "=>", "'formbuttons'", ")", ",", "html", "::", "tag", "(", "'input'", ",", "array", "(", "'type'", "=>", "'submit'", ",", "'class'", "=>", "'button mainaction'", ",", "'value'", "=>", "$", "this", "->", "gettext", "(", "'save'", ")", ")", ")", ")", ")", ")", ";", "$", "title", "=", "rcube", "::", "JQ", "(", "$", "this", "->", "gettext", "(", "'identitydialogtitle'", ")", ")", ";", "$", "script", "=", "\"\n$('#newuserdialog').show()\n .dialog({modal:true, resizable:false, closeOnEscape:false, width:450, title:'$title'})\n .submit(function() {\n var i, request = {}, form = $(this).serializeArray();\n for (i in form)\n request[form[i].name] = form[i].value;\n\n rcmail.http_post('plugin.newusersave', request, true);\n return false;\n });\n\n$('input[name=_name]').focus();\nrcube_webmail.prototype.new_user_dialog_close = function() { $('#newuserdialog').dialog('close'); }\n\"", ";", "// disable keyboard events for messages list (#1486726)", "$", "rcmail", "->", "output", "->", "add_script", "(", "$", "script", ",", "'docready'", ")", ";", "$", "this", "->", "include_stylesheet", "(", "'newuserdialog.css'", ")", ";", "}", "}" ]
Callback function when HTML page is rendered We'll add an overlay box here.
[ "Callback", "function", "when", "HTML", "page", "is", "rendered", "We", "ll", "add", "an", "overlay", "box", "here", "." ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/plugins/new_user_dialog/new_user_dialog.php#L46-L124
train
i-MSCP/roundcube
roundcubemail/plugins/enigma/lib/enigma_ui.php
enigma_ui.init
function init() { $this->add_js(); $action = rcube_utils::get_input_value('_a', rcube_utils::INPUT_GPC); if ($this->rc->action == 'plugin.enigmakeys') { switch ($action) { case 'delete': $this->key_delete(); break; /* case 'edit': $this->key_edit(); break; */ case 'import': $this->key_import(); break; case 'export': $this->key_export(); break; case 'generate': $this->key_generate(); break; case 'create': $this->key_create(); break; case 'search': case 'list': $this->key_list(); break; case 'info': $this->key_info(); break; } $this->rc->output->add_handlers(array( 'keyslist' => array($this, 'tpl_keys_list'), 'keyframe' => array($this, 'tpl_key_frame'), 'countdisplay' => array($this, 'tpl_keys_rowcount'), 'searchform' => array($this->rc->output, 'search_form'), )); $this->rc->output->set_pagetitle($this->enigma->gettext('enigmakeys')); $this->rc->output->send('enigma.keys'); } /* // Preferences UI else if ($this->rc->action == 'plugin.enigmacerts') { $this->rc->output->add_handlers(array( 'keyslist' => array($this, 'tpl_certs_list'), 'keyframe' => array($this, 'tpl_cert_frame'), 'countdisplay' => array($this, 'tpl_certs_rowcount'), 'searchform' => array($this->rc->output, 'search_form'), )); $this->rc->output->set_pagetitle($this->enigma->gettext('enigmacerts')); $this->rc->output->send('enigma.certs'); } */ // Message composing UI else if ($this->rc->action == 'compose') { $this->compose_ui(); } }
php
function init() { $this->add_js(); $action = rcube_utils::get_input_value('_a', rcube_utils::INPUT_GPC); if ($this->rc->action == 'plugin.enigmakeys') { switch ($action) { case 'delete': $this->key_delete(); break; /* case 'edit': $this->key_edit(); break; */ case 'import': $this->key_import(); break; case 'export': $this->key_export(); break; case 'generate': $this->key_generate(); break; case 'create': $this->key_create(); break; case 'search': case 'list': $this->key_list(); break; case 'info': $this->key_info(); break; } $this->rc->output->add_handlers(array( 'keyslist' => array($this, 'tpl_keys_list'), 'keyframe' => array($this, 'tpl_key_frame'), 'countdisplay' => array($this, 'tpl_keys_rowcount'), 'searchform' => array($this->rc->output, 'search_form'), )); $this->rc->output->set_pagetitle($this->enigma->gettext('enigmakeys')); $this->rc->output->send('enigma.keys'); } /* // Preferences UI else if ($this->rc->action == 'plugin.enigmacerts') { $this->rc->output->add_handlers(array( 'keyslist' => array($this, 'tpl_certs_list'), 'keyframe' => array($this, 'tpl_cert_frame'), 'countdisplay' => array($this, 'tpl_certs_rowcount'), 'searchform' => array($this->rc->output, 'search_form'), )); $this->rc->output->set_pagetitle($this->enigma->gettext('enigmacerts')); $this->rc->output->send('enigma.certs'); } */ // Message composing UI else if ($this->rc->action == 'compose') { $this->compose_ui(); } }
[ "function", "init", "(", ")", "{", "$", "this", "->", "add_js", "(", ")", ";", "$", "action", "=", "rcube_utils", "::", "get_input_value", "(", "'_a'", ",", "rcube_utils", "::", "INPUT_GPC", ")", ";", "if", "(", "$", "this", "->", "rc", "->", "action", "==", "'plugin.enigmakeys'", ")", "{", "switch", "(", "$", "action", ")", "{", "case", "'delete'", ":", "$", "this", "->", "key_delete", "(", ")", ";", "break", ";", "/*\n case 'edit':\n $this->key_edit();\n break;\n*/", "case", "'import'", ":", "$", "this", "->", "key_import", "(", ")", ";", "break", ";", "case", "'export'", ":", "$", "this", "->", "key_export", "(", ")", ";", "break", ";", "case", "'generate'", ":", "$", "this", "->", "key_generate", "(", ")", ";", "break", ";", "case", "'create'", ":", "$", "this", "->", "key_create", "(", ")", ";", "break", ";", "case", "'search'", ":", "case", "'list'", ":", "$", "this", "->", "key_list", "(", ")", ";", "break", ";", "case", "'info'", ":", "$", "this", "->", "key_info", "(", ")", ";", "break", ";", "}", "$", "this", "->", "rc", "->", "output", "->", "add_handlers", "(", "array", "(", "'keyslist'", "=>", "array", "(", "$", "this", ",", "'tpl_keys_list'", ")", ",", "'keyframe'", "=>", "array", "(", "$", "this", ",", "'tpl_key_frame'", ")", ",", "'countdisplay'", "=>", "array", "(", "$", "this", ",", "'tpl_keys_rowcount'", ")", ",", "'searchform'", "=>", "array", "(", "$", "this", "->", "rc", "->", "output", ",", "'search_form'", ")", ",", ")", ")", ";", "$", "this", "->", "rc", "->", "output", "->", "set_pagetitle", "(", "$", "this", "->", "enigma", "->", "gettext", "(", "'enigmakeys'", ")", ")", ";", "$", "this", "->", "rc", "->", "output", "->", "send", "(", "'enigma.keys'", ")", ";", "}", "/*\n // Preferences UI\n else if ($this->rc->action == 'plugin.enigmacerts') {\n $this->rc->output->add_handlers(array(\n 'keyslist' => array($this, 'tpl_certs_list'),\n 'keyframe' => array($this, 'tpl_cert_frame'),\n 'countdisplay' => array($this, 'tpl_certs_rowcount'),\n 'searchform' => array($this->rc->output, 'search_form'),\n ));\n\n $this->rc->output->set_pagetitle($this->enigma->gettext('enigmacerts'));\n $this->rc->output->send('enigma.certs'); \n }\n*/", "// Message composing UI", "else", "if", "(", "$", "this", "->", "rc", "->", "action", "==", "'compose'", ")", "{", "$", "this", "->", "compose_ui", "(", ")", ";", "}", "}" ]
UI initialization and requests handlers. @param string Preferences section
[ "UI", "initialization", "and", "requests", "handlers", "." ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/plugins/enigma/lib/enigma_ui.php#L42-L112
train
i-MSCP/roundcube
roundcubemail/plugins/enigma/lib/enigma_ui.php
enigma_ui.add_css
function add_css() { if ($this->css_loaded) { return; } $skin_path = $this->enigma->local_skin_path(); $this->enigma->include_stylesheet("$skin_path/enigma.css"); $this->css_loaded = true; }
php
function add_css() { if ($this->css_loaded) { return; } $skin_path = $this->enigma->local_skin_path(); $this->enigma->include_stylesheet("$skin_path/enigma.css"); $this->css_loaded = true; }
[ "function", "add_css", "(", ")", "{", "if", "(", "$", "this", "->", "css_loaded", ")", "{", "return", ";", "}", "$", "skin_path", "=", "$", "this", "->", "enigma", "->", "local_skin_path", "(", ")", ";", "$", "this", "->", "enigma", "->", "include_stylesheet", "(", "\"$skin_path/enigma.css\"", ")", ";", "$", "this", "->", "css_loaded", "=", "true", ";", "}" ]
Adds CSS style file to the page header.
[ "Adds", "CSS", "style", "file", "to", "the", "page", "header", "." ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/plugins/enigma/lib/enigma_ui.php#L117-L126
train
i-MSCP/roundcube
roundcubemail/plugins/enigma/lib/enigma_ui.php
enigma_ui.password_prompt
function password_prompt($status, $params = array()) { $data = $status->getData('missing'); if (empty($data)) { $data = $status->getData('bad'); } $keyid = key($data); $data = array( 'keyid' => $params['keyid'] ?: $keyid, 'user' => $data[$keyid] ); // With GnuPG 2.1 user name may not be specified (e.g. on private // key export), we'll get the key information and set the name appropriately if ($keyid && $params['keyid'] && strpos($data['user'], $keyid) !== false) { $key = $this->enigma->engine->get_key($params['keyid']); if ($key && $key->name) { $data['user'] = $key->name; } } if (!empty($params)) { $data = array_merge($params, $data); } if (preg_match('/^(send|plugin.enigmaimport|plugin.enigmakeys)$/', $this->rc->action)) { $this->rc->output->command('enigma_password_request', $data); } else { $this->rc->output->set_env('enigma_password_request', $data); } // add some labels to client $this->rc->output->add_label('enigma.enterkeypasstitle', 'enigma.enterkeypass', 'save', 'cancel'); $this->add_css(); $this->add_js(); }
php
function password_prompt($status, $params = array()) { $data = $status->getData('missing'); if (empty($data)) { $data = $status->getData('bad'); } $keyid = key($data); $data = array( 'keyid' => $params['keyid'] ?: $keyid, 'user' => $data[$keyid] ); // With GnuPG 2.1 user name may not be specified (e.g. on private // key export), we'll get the key information and set the name appropriately if ($keyid && $params['keyid'] && strpos($data['user'], $keyid) !== false) { $key = $this->enigma->engine->get_key($params['keyid']); if ($key && $key->name) { $data['user'] = $key->name; } } if (!empty($params)) { $data = array_merge($params, $data); } if (preg_match('/^(send|plugin.enigmaimport|plugin.enigmakeys)$/', $this->rc->action)) { $this->rc->output->command('enigma_password_request', $data); } else { $this->rc->output->set_env('enigma_password_request', $data); } // add some labels to client $this->rc->output->add_label('enigma.enterkeypasstitle', 'enigma.enterkeypass', 'save', 'cancel'); $this->add_css(); $this->add_js(); }
[ "function", "password_prompt", "(", "$", "status", ",", "$", "params", "=", "array", "(", ")", ")", "{", "$", "data", "=", "$", "status", "->", "getData", "(", "'missing'", ")", ";", "if", "(", "empty", "(", "$", "data", ")", ")", "{", "$", "data", "=", "$", "status", "->", "getData", "(", "'bad'", ")", ";", "}", "$", "keyid", "=", "key", "(", "$", "data", ")", ";", "$", "data", "=", "array", "(", "'keyid'", "=>", "$", "params", "[", "'keyid'", "]", "?", ":", "$", "keyid", ",", "'user'", "=>", "$", "data", "[", "$", "keyid", "]", ")", ";", "// With GnuPG 2.1 user name may not be specified (e.g. on private", "// key export), we'll get the key information and set the name appropriately", "if", "(", "$", "keyid", "&&", "$", "params", "[", "'keyid'", "]", "&&", "strpos", "(", "$", "data", "[", "'user'", "]", ",", "$", "keyid", ")", "!==", "false", ")", "{", "$", "key", "=", "$", "this", "->", "enigma", "->", "engine", "->", "get_key", "(", "$", "params", "[", "'keyid'", "]", ")", ";", "if", "(", "$", "key", "&&", "$", "key", "->", "name", ")", "{", "$", "data", "[", "'user'", "]", "=", "$", "key", "->", "name", ";", "}", "}", "if", "(", "!", "empty", "(", "$", "params", ")", ")", "{", "$", "data", "=", "array_merge", "(", "$", "params", ",", "$", "data", ")", ";", "}", "if", "(", "preg_match", "(", "'/^(send|plugin.enigmaimport|plugin.enigmakeys)$/'", ",", "$", "this", "->", "rc", "->", "action", ")", ")", "{", "$", "this", "->", "rc", "->", "output", "->", "command", "(", "'enigma_password_request'", ",", "$", "data", ")", ";", "}", "else", "{", "$", "this", "->", "rc", "->", "output", "->", "set_env", "(", "'enigma_password_request'", ",", "$", "data", ")", ";", "}", "// add some labels to client", "$", "this", "->", "rc", "->", "output", "->", "add_label", "(", "'enigma.enterkeypasstitle'", ",", "'enigma.enterkeypass'", ",", "'save'", ",", "'cancel'", ")", ";", "$", "this", "->", "add_css", "(", ")", ";", "$", "this", "->", "add_js", "(", ")", ";", "}" ]
Initializes key password prompt @param enigma_error $status Error object with key info @param array $params Optional prompt parameters
[ "Initializes", "key", "password", "prompt" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/plugins/enigma/lib/enigma_ui.php#L148-L188
train
i-MSCP/roundcube
roundcubemail/plugins/enigma/lib/enigma_ui.php
enigma_ui.tpl_keys_list
function tpl_keys_list($attrib) { // add id to message list table if not specified if (!strlen($attrib['id'])) { $attrib['id'] = 'rcmenigmakeyslist'; } // define list of cols to be displayed $a_show_cols = array('name'); // create XHTML table $out = $this->rc->table_output($attrib, array(), $a_show_cols, 'id'); // set client env $this->rc->output->add_gui_object('keyslist', $attrib['id']); $this->rc->output->include_script('list.js'); // add some labels to client $this->rc->output->add_label('enigma.keyremoveconfirm', 'enigma.keyremoving', 'enigma.keyexportprompt', 'enigma.withprivkeys', 'enigma.onlypubkeys', 'enigma.exportkeys' ); return $out; }
php
function tpl_keys_list($attrib) { // add id to message list table if not specified if (!strlen($attrib['id'])) { $attrib['id'] = 'rcmenigmakeyslist'; } // define list of cols to be displayed $a_show_cols = array('name'); // create XHTML table $out = $this->rc->table_output($attrib, array(), $a_show_cols, 'id'); // set client env $this->rc->output->add_gui_object('keyslist', $attrib['id']); $this->rc->output->include_script('list.js'); // add some labels to client $this->rc->output->add_label('enigma.keyremoveconfirm', 'enigma.keyremoving', 'enigma.keyexportprompt', 'enigma.withprivkeys', 'enigma.onlypubkeys', 'enigma.exportkeys' ); return $out; }
[ "function", "tpl_keys_list", "(", "$", "attrib", ")", "{", "// add id to message list table if not specified", "if", "(", "!", "strlen", "(", "$", "attrib", "[", "'id'", "]", ")", ")", "{", "$", "attrib", "[", "'id'", "]", "=", "'rcmenigmakeyslist'", ";", "}", "// define list of cols to be displayed", "$", "a_show_cols", "=", "array", "(", "'name'", ")", ";", "// create XHTML table", "$", "out", "=", "$", "this", "->", "rc", "->", "table_output", "(", "$", "attrib", ",", "array", "(", ")", ",", "$", "a_show_cols", ",", "'id'", ")", ";", "// set client env", "$", "this", "->", "rc", "->", "output", "->", "add_gui_object", "(", "'keyslist'", ",", "$", "attrib", "[", "'id'", "]", ")", ";", "$", "this", "->", "rc", "->", "output", "->", "include_script", "(", "'list.js'", ")", ";", "// add some labels to client", "$", "this", "->", "rc", "->", "output", "->", "add_label", "(", "'enigma.keyremoveconfirm'", ",", "'enigma.keyremoving'", ",", "'enigma.keyexportprompt'", ",", "'enigma.withprivkeys'", ",", "'enigma.onlypubkeys'", ",", "'enigma.exportkeys'", ")", ";", "return", "$", "out", ";", "}" ]
Template object for list of keys. @param array Object attributes @return string HTML content
[ "Template", "object", "for", "list", "of", "keys", "." ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/plugins/enigma/lib/enigma_ui.php#L209-L232
train
i-MSCP/roundcube
roundcubemail/plugins/enigma/lib/enigma_ui.php
enigma_ui.tpl_keys_rowcount
function tpl_keys_rowcount($attrib) { if (!$attrib['id']) $attrib['id'] = 'rcmcountdisplay'; $this->rc->output->add_gui_object('countdisplay', $attrib['id']); return html::span($attrib, $this->get_rowcount_text()); }
php
function tpl_keys_rowcount($attrib) { if (!$attrib['id']) $attrib['id'] = 'rcmcountdisplay'; $this->rc->output->add_gui_object('countdisplay', $attrib['id']); return html::span($attrib, $this->get_rowcount_text()); }
[ "function", "tpl_keys_rowcount", "(", "$", "attrib", ")", "{", "if", "(", "!", "$", "attrib", "[", "'id'", "]", ")", "$", "attrib", "[", "'id'", "]", "=", "'rcmcountdisplay'", ";", "$", "this", "->", "rc", "->", "output", "->", "add_gui_object", "(", "'countdisplay'", ",", "$", "attrib", "[", "'id'", "]", ")", ";", "return", "html", "::", "span", "(", "$", "attrib", ",", "$", "this", "->", "get_rowcount_text", "(", ")", ")", ";", "}" ]
Template object for list records counter. @param array Object attributes @return string HTML output
[ "Template", "object", "for", "list", "records", "counter", "." ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/plugins/enigma/lib/enigma_ui.php#L290-L298
train
i-MSCP/roundcube
roundcubemail/plugins/enigma/lib/enigma_ui.php
enigma_ui.get_rowcount_text
private function get_rowcount_text($all=0, $curr_count=0, $page=1) { if (!$curr_count) { $out = $this->enigma->gettext('nokeysfound'); } else { $pagesize = $this->rc->config->get('pagesize', 100); $first = ($page - 1) * $pagesize; $out = $this->enigma->gettext(array( 'name' => 'keysfromto', 'vars' => array( 'from' => $first + 1, 'to' => $first + $curr_count, 'count' => $all) )); } return $out; }
php
private function get_rowcount_text($all=0, $curr_count=0, $page=1) { if (!$curr_count) { $out = $this->enigma->gettext('nokeysfound'); } else { $pagesize = $this->rc->config->get('pagesize', 100); $first = ($page - 1) * $pagesize; $out = $this->enigma->gettext(array( 'name' => 'keysfromto', 'vars' => array( 'from' => $first + 1, 'to' => $first + $curr_count, 'count' => $all) )); } return $out; }
[ "private", "function", "get_rowcount_text", "(", "$", "all", "=", "0", ",", "$", "curr_count", "=", "0", ",", "$", "page", "=", "1", ")", "{", "if", "(", "!", "$", "curr_count", ")", "{", "$", "out", "=", "$", "this", "->", "enigma", "->", "gettext", "(", "'nokeysfound'", ")", ";", "}", "else", "{", "$", "pagesize", "=", "$", "this", "->", "rc", "->", "config", "->", "get", "(", "'pagesize'", ",", "100", ")", ";", "$", "first", "=", "(", "$", "page", "-", "1", ")", "*", "$", "pagesize", ";", "$", "out", "=", "$", "this", "->", "enigma", "->", "gettext", "(", "array", "(", "'name'", "=>", "'keysfromto'", ",", "'vars'", "=>", "array", "(", "'from'", "=>", "$", "first", "+", "1", ",", "'to'", "=>", "$", "first", "+", "$", "curr_count", ",", "'count'", "=>", "$", "all", ")", ")", ")", ";", "}", "return", "$", "out", ";", "}" ]
Returns text representation of list records counter
[ "Returns", "text", "representation", "of", "list", "records", "counter" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/plugins/enigma/lib/enigma_ui.php#L303-L322
train
i-MSCP/roundcube
roundcubemail/plugins/enigma/lib/enigma_ui.php
enigma_ui.key_info
private function key_info() { $this->enigma->load_engine(); $id = rcube_utils::get_input_value('_id', rcube_utils::INPUT_GET); $res = $this->enigma->engine->get_key($id); if ($res instanceof enigma_key) { $this->data = $res; } else { // error $this->rc->output->show_message('enigma.keyopenerror', 'error'); $this->rc->output->command('parent.enigma_loadframe'); $this->rc->output->send('iframe'); } $this->rc->output->add_handlers(array( 'keyname' => array($this, 'tpl_key_name'), 'keydata' => array($this, 'tpl_key_data'), )); $this->rc->output->set_pagetitle($this->enigma->gettext('keyinfo')); $this->rc->output->send('enigma.keyinfo'); }
php
private function key_info() { $this->enigma->load_engine(); $id = rcube_utils::get_input_value('_id', rcube_utils::INPUT_GET); $res = $this->enigma->engine->get_key($id); if ($res instanceof enigma_key) { $this->data = $res; } else { // error $this->rc->output->show_message('enigma.keyopenerror', 'error'); $this->rc->output->command('parent.enigma_loadframe'); $this->rc->output->send('iframe'); } $this->rc->output->add_handlers(array( 'keyname' => array($this, 'tpl_key_name'), 'keydata' => array($this, 'tpl_key_data'), )); $this->rc->output->set_pagetitle($this->enigma->gettext('keyinfo')); $this->rc->output->send('enigma.keyinfo'); }
[ "private", "function", "key_info", "(", ")", "{", "$", "this", "->", "enigma", "->", "load_engine", "(", ")", ";", "$", "id", "=", "rcube_utils", "::", "get_input_value", "(", "'_id'", ",", "rcube_utils", "::", "INPUT_GET", ")", ";", "$", "res", "=", "$", "this", "->", "enigma", "->", "engine", "->", "get_key", "(", "$", "id", ")", ";", "if", "(", "$", "res", "instanceof", "enigma_key", ")", "{", "$", "this", "->", "data", "=", "$", "res", ";", "}", "else", "{", "// error", "$", "this", "->", "rc", "->", "output", "->", "show_message", "(", "'enigma.keyopenerror'", ",", "'error'", ")", ";", "$", "this", "->", "rc", "->", "output", "->", "command", "(", "'parent.enigma_loadframe'", ")", ";", "$", "this", "->", "rc", "->", "output", "->", "send", "(", "'iframe'", ")", ";", "}", "$", "this", "->", "rc", "->", "output", "->", "add_handlers", "(", "array", "(", "'keyname'", "=>", "array", "(", "$", "this", ",", "'tpl_key_name'", ")", ",", "'keydata'", "=>", "array", "(", "$", "this", ",", "'tpl_key_data'", ")", ",", ")", ")", ";", "$", "this", "->", "rc", "->", "output", "->", "set_pagetitle", "(", "$", "this", "->", "enigma", "->", "gettext", "(", "'keyinfo'", ")", ")", ";", "$", "this", "->", "rc", "->", "output", "->", "send", "(", "'enigma.keyinfo'", ")", ";", "}" ]
Key information page handler
[ "Key", "information", "page", "handler" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/plugins/enigma/lib/enigma_ui.php#L327-L350
train
i-MSCP/roundcube
roundcubemail/plugins/enigma/lib/enigma_ui.php
enigma_ui.key_generate
private function key_generate() { // Crypt_GPG does not support key generation for multiple identities // It is also very slow (which is problematic because it may exceed // request time limit) and requires entropy generator // That's why we use only OpenPGP.js method of key generation return; $user = rcube_utils::get_input_value('_user', rcube_utils::INPUT_POST, true); $pass = rcube_utils::get_input_value('_password', rcube_utils::INPUT_POST, true); $size = (int) rcube_utils::get_input_value('_size', rcube_utils::INPUT_POST); if ($size > 4096) { $size = 4096; } $ident = rcube_mime::decode_address_list($user, 1, false); if (empty($ident)) { $this->rc->output->show_message('enigma.keygenerateerror', 'error'); $this->rc->output->send(); } $this->enigma->load_engine(); $result = $this->enigma->engine->generate_key(array( 'user' => $ident[1]['name'], 'email' => $ident[1]['mailto'], 'password' => $pass, 'size' => $size, )); if ($result instanceof enigma_key) { $this->rc->output->command('enigma_key_create_success'); $this->rc->output->show_message('enigma.keygeneratesuccess', 'confirmation'); } else { $this->rc->output->show_message('enigma.keygenerateerror', 'error'); } $this->rc->output->send(); }
php
private function key_generate() { // Crypt_GPG does not support key generation for multiple identities // It is also very slow (which is problematic because it may exceed // request time limit) and requires entropy generator // That's why we use only OpenPGP.js method of key generation return; $user = rcube_utils::get_input_value('_user', rcube_utils::INPUT_POST, true); $pass = rcube_utils::get_input_value('_password', rcube_utils::INPUT_POST, true); $size = (int) rcube_utils::get_input_value('_size', rcube_utils::INPUT_POST); if ($size > 4096) { $size = 4096; } $ident = rcube_mime::decode_address_list($user, 1, false); if (empty($ident)) { $this->rc->output->show_message('enigma.keygenerateerror', 'error'); $this->rc->output->send(); } $this->enigma->load_engine(); $result = $this->enigma->engine->generate_key(array( 'user' => $ident[1]['name'], 'email' => $ident[1]['mailto'], 'password' => $pass, 'size' => $size, )); if ($result instanceof enigma_key) { $this->rc->output->command('enigma_key_create_success'); $this->rc->output->show_message('enigma.keygeneratesuccess', 'confirmation'); } else { $this->rc->output->show_message('enigma.keygenerateerror', 'error'); } $this->rc->output->send(); }
[ "private", "function", "key_generate", "(", ")", "{", "// Crypt_GPG does not support key generation for multiple identities", "// It is also very slow (which is problematic because it may exceed", "// request time limit) and requires entropy generator", "// That's why we use only OpenPGP.js method of key generation", "return", ";", "$", "user", "=", "rcube_utils", "::", "get_input_value", "(", "'_user'", ",", "rcube_utils", "::", "INPUT_POST", ",", "true", ")", ";", "$", "pass", "=", "rcube_utils", "::", "get_input_value", "(", "'_password'", ",", "rcube_utils", "::", "INPUT_POST", ",", "true", ")", ";", "$", "size", "=", "(", "int", ")", "rcube_utils", "::", "get_input_value", "(", "'_size'", ",", "rcube_utils", "::", "INPUT_POST", ")", ";", "if", "(", "$", "size", ">", "4096", ")", "{", "$", "size", "=", "4096", ";", "}", "$", "ident", "=", "rcube_mime", "::", "decode_address_list", "(", "$", "user", ",", "1", ",", "false", ")", ";", "if", "(", "empty", "(", "$", "ident", ")", ")", "{", "$", "this", "->", "rc", "->", "output", "->", "show_message", "(", "'enigma.keygenerateerror'", ",", "'error'", ")", ";", "$", "this", "->", "rc", "->", "output", "->", "send", "(", ")", ";", "}", "$", "this", "->", "enigma", "->", "load_engine", "(", ")", ";", "$", "result", "=", "$", "this", "->", "enigma", "->", "engine", "->", "generate_key", "(", "array", "(", "'user'", "=>", "$", "ident", "[", "1", "]", "[", "'name'", "]", ",", "'email'", "=>", "$", "ident", "[", "1", "]", "[", "'mailto'", "]", ",", "'password'", "=>", "$", "pass", ",", "'size'", "=>", "$", "size", ",", ")", ")", ";", "if", "(", "$", "result", "instanceof", "enigma_key", ")", "{", "$", "this", "->", "rc", "->", "output", "->", "command", "(", "'enigma_key_create_success'", ")", ";", "$", "this", "->", "rc", "->", "output", "->", "show_message", "(", "'enigma.keygeneratesuccess'", ",", "'confirmation'", ")", ";", "}", "else", "{", "$", "this", "->", "rc", "->", "output", "->", "show_message", "(", "'enigma.keygenerateerror'", ",", "'error'", ")", ";", "}", "$", "this", "->", "rc", "->", "output", "->", "send", "(", ")", ";", "}" ]
Server-side key pair generation handler
[ "Server", "-", "side", "key", "pair", "generation", "handler" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/plugins/enigma/lib/enigma_ui.php#L656-L696
train
i-MSCP/roundcube
roundcubemail/plugins/enigma/lib/enigma_ui.php
enigma_ui.key_create
private function key_create() { $this->enigma->include_script('openpgp.min.js'); $this->rc->output->add_handlers(array( 'keyform' => array($this, 'tpl_key_create_form'), )); $this->rc->output->set_pagetitle($this->enigma->gettext('keygenerate')); $this->rc->output->send('enigma.keycreate'); }
php
private function key_create() { $this->enigma->include_script('openpgp.min.js'); $this->rc->output->add_handlers(array( 'keyform' => array($this, 'tpl_key_create_form'), )); $this->rc->output->set_pagetitle($this->enigma->gettext('keygenerate')); $this->rc->output->send('enigma.keycreate'); }
[ "private", "function", "key_create", "(", ")", "{", "$", "this", "->", "enigma", "->", "include_script", "(", "'openpgp.min.js'", ")", ";", "$", "this", "->", "rc", "->", "output", "->", "add_handlers", "(", "array", "(", "'keyform'", "=>", "array", "(", "$", "this", ",", "'tpl_key_create_form'", ")", ",", ")", ")", ";", "$", "this", "->", "rc", "->", "output", "->", "set_pagetitle", "(", "$", "this", "->", "enigma", "->", "gettext", "(", "'keygenerate'", ")", ")", ";", "$", "this", "->", "rc", "->", "output", "->", "send", "(", "'enigma.keycreate'", ")", ";", "}" ]
Key generation page handler
[ "Key", "generation", "page", "handler" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/plugins/enigma/lib/enigma_ui.php#L701-L711
train
i-MSCP/roundcube
roundcubemail/plugins/enigma/lib/enigma_ui.php
enigma_ui.message_compose
function message_compose($p) { $engine = $this->enigma->load_engine(); // skip: message has no signed/encoded content if (!$this->enigma->engine) { return $p; } $engine = $this->enigma->engine; $locks = (array) $this->rc->config->get('enigma_options_lock'); // Decryption status foreach ($engine->decryptions as $status) { if ($status instanceof enigma_error) { $code = $status->getCode(); if ($code == enigma_error::KEYNOTFOUND) { $msg = rcube::Q(str_replace('$keyid', enigma_key::format_id($status->getData('id')), $this->enigma->gettext('decryptnokey'))); } else if ($code == enigma_error::BADPASS) { $this->password_prompt($status, array('compose-init' => true)); return $p; } else { $msg = rcube::Q($this->enigma->gettext('decrypterror')); } } } if ($msg) { $this->rc->output->show_message($msg, 'error'); } // Check sign/ecrypt options for signed/encrypted drafts if (!in_array('encrypt', $locks)) { $this->rc->output->set_env('enigma_force_encrypt', !empty($engine->decryptions)); } if (!in_array('sign', $locks)) { $this->rc->output->set_env('enigma_force_sign', !empty($engine->signatures)); } return $p; }
php
function message_compose($p) { $engine = $this->enigma->load_engine(); // skip: message has no signed/encoded content if (!$this->enigma->engine) { return $p; } $engine = $this->enigma->engine; $locks = (array) $this->rc->config->get('enigma_options_lock'); // Decryption status foreach ($engine->decryptions as $status) { if ($status instanceof enigma_error) { $code = $status->getCode(); if ($code == enigma_error::KEYNOTFOUND) { $msg = rcube::Q(str_replace('$keyid', enigma_key::format_id($status->getData('id')), $this->enigma->gettext('decryptnokey'))); } else if ($code == enigma_error::BADPASS) { $this->password_prompt($status, array('compose-init' => true)); return $p; } else { $msg = rcube::Q($this->enigma->gettext('decrypterror')); } } } if ($msg) { $this->rc->output->show_message($msg, 'error'); } // Check sign/ecrypt options for signed/encrypted drafts if (!in_array('encrypt', $locks)) { $this->rc->output->set_env('enigma_force_encrypt', !empty($engine->decryptions)); } if (!in_array('sign', $locks)) { $this->rc->output->set_env('enigma_force_sign', !empty($engine->signatures)); } return $p; }
[ "function", "message_compose", "(", "$", "p", ")", "{", "$", "engine", "=", "$", "this", "->", "enigma", "->", "load_engine", "(", ")", ";", "// skip: message has no signed/encoded content", "if", "(", "!", "$", "this", "->", "enigma", "->", "engine", ")", "{", "return", "$", "p", ";", "}", "$", "engine", "=", "$", "this", "->", "enigma", "->", "engine", ";", "$", "locks", "=", "(", "array", ")", "$", "this", "->", "rc", "->", "config", "->", "get", "(", "'enigma_options_lock'", ")", ";", "// Decryption status", "foreach", "(", "$", "engine", "->", "decryptions", "as", "$", "status", ")", "{", "if", "(", "$", "status", "instanceof", "enigma_error", ")", "{", "$", "code", "=", "$", "status", "->", "getCode", "(", ")", ";", "if", "(", "$", "code", "==", "enigma_error", "::", "KEYNOTFOUND", ")", "{", "$", "msg", "=", "rcube", "::", "Q", "(", "str_replace", "(", "'$keyid'", ",", "enigma_key", "::", "format_id", "(", "$", "status", "->", "getData", "(", "'id'", ")", ")", ",", "$", "this", "->", "enigma", "->", "gettext", "(", "'decryptnokey'", ")", ")", ")", ";", "}", "else", "if", "(", "$", "code", "==", "enigma_error", "::", "BADPASS", ")", "{", "$", "this", "->", "password_prompt", "(", "$", "status", ",", "array", "(", "'compose-init'", "=>", "true", ")", ")", ";", "return", "$", "p", ";", "}", "else", "{", "$", "msg", "=", "rcube", "::", "Q", "(", "$", "this", "->", "enigma", "->", "gettext", "(", "'decrypterror'", ")", ")", ";", "}", "}", "}", "if", "(", "$", "msg", ")", "{", "$", "this", "->", "rc", "->", "output", "->", "show_message", "(", "$", "msg", ",", "'error'", ")", ";", "}", "// Check sign/ecrypt options for signed/encrypted drafts", "if", "(", "!", "in_array", "(", "'encrypt'", ",", "$", "locks", ")", ")", "{", "$", "this", "->", "rc", "->", "output", "->", "set_env", "(", "'enigma_force_encrypt'", ",", "!", "empty", "(", "$", "engine", "->", "decryptions", ")", ")", ";", "}", "if", "(", "!", "in_array", "(", "'sign'", ",", "$", "locks", ")", ")", "{", "$", "this", "->", "rc", "->", "output", "->", "set_env", "(", "'enigma_force_sign'", ",", "!", "empty", "(", "$", "engine", "->", "signatures", ")", ")", ";", "}", "return", "$", "p", ";", "}" ]
Handler for message_compose_body hook Display error when the message cannot be encrypted and provide a way to try again with a password.
[ "Handler", "for", "message_compose_body", "hook", "Display", "error", "when", "the", "message", "cannot", "be", "encrypted", "and", "provide", "a", "way", "to", "try", "again", "with", "a", "password", "." ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/plugins/enigma/lib/enigma_ui.php#L1140-L1184
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_text2html.php
rcube_text2html._convert_line
protected function _convert_line($text, $is_flowed) { static $table; if (empty($table)) { $table = get_html_translation_table(HTML_SPECIALCHARS); unset($table['?']); // replace some whitespace characters $table["\r"] = ''; $table["\t"] = ' '; } // skip signature separator if ($text == '-- ') { return '--' . $this->config['space']; } // replace HTML special and whitespace characters $text = strtr($text, $table); $nbsp = $this->config['space']; // replace spaces with non-breaking spaces if ($is_flowed) { $pos = 0; $diff = 0; $len = strlen($nbsp); $copy = $text; while (($pos = strpos($text, ' ', $pos)) !== false) { if ($pos == 0 || $text[$pos-1] == ' ') { $copy = substr_replace($copy, $nbsp, $pos + $diff, 1); $diff += $len - 1; } $pos++; } $text = $copy; } // make the whole line non-breakable if needed else if ($text !== '' && preg_match('/[^a-zA-Z0-9_]/', $text)) { // use non-breakable spaces to correctly display // trailing/leading spaces and multi-space inside $text = str_replace(' ', $nbsp, $text); // wrap in nobr element, so it's not wrapped on e.g. - or / $text = $this->config['nobr_start'] . $text . $this->config['nobr_end']; } return $text; }
php
protected function _convert_line($text, $is_flowed) { static $table; if (empty($table)) { $table = get_html_translation_table(HTML_SPECIALCHARS); unset($table['?']); // replace some whitespace characters $table["\r"] = ''; $table["\t"] = ' '; } // skip signature separator if ($text == '-- ') { return '--' . $this->config['space']; } // replace HTML special and whitespace characters $text = strtr($text, $table); $nbsp = $this->config['space']; // replace spaces with non-breaking spaces if ($is_flowed) { $pos = 0; $diff = 0; $len = strlen($nbsp); $copy = $text; while (($pos = strpos($text, ' ', $pos)) !== false) { if ($pos == 0 || $text[$pos-1] == ' ') { $copy = substr_replace($copy, $nbsp, $pos + $diff, 1); $diff += $len - 1; } $pos++; } $text = $copy; } // make the whole line non-breakable if needed else if ($text !== '' && preg_match('/[^a-zA-Z0-9_]/', $text)) { // use non-breakable spaces to correctly display // trailing/leading spaces and multi-space inside $text = str_replace(' ', $nbsp, $text); // wrap in nobr element, so it's not wrapped on e.g. - or / $text = $this->config['nobr_start'] . $text . $this->config['nobr_end']; } return $text; }
[ "protected", "function", "_convert_line", "(", "$", "text", ",", "$", "is_flowed", ")", "{", "static", "$", "table", ";", "if", "(", "empty", "(", "$", "table", ")", ")", "{", "$", "table", "=", "get_html_translation_table", "(", "HTML_SPECIALCHARS", ")", ";", "unset", "(", "$", "table", "[", "'?'", "]", ")", ";", "// replace some whitespace characters", "$", "table", "[", "\"\\r\"", "]", "=", "''", ";", "$", "table", "[", "\"\\t\"", "]", "=", "' '", ";", "}", "// skip signature separator", "if", "(", "$", "text", "==", "'-- '", ")", "{", "return", "'--'", ".", "$", "this", "->", "config", "[", "'space'", "]", ";", "}", "// replace HTML special and whitespace characters", "$", "text", "=", "strtr", "(", "$", "text", ",", "$", "table", ")", ";", "$", "nbsp", "=", "$", "this", "->", "config", "[", "'space'", "]", ";", "// replace spaces with non-breaking spaces", "if", "(", "$", "is_flowed", ")", "{", "$", "pos", "=", "0", ";", "$", "diff", "=", "0", ";", "$", "len", "=", "strlen", "(", "$", "nbsp", ")", ";", "$", "copy", "=", "$", "text", ";", "while", "(", "(", "$", "pos", "=", "strpos", "(", "$", "text", ",", "' '", ",", "$", "pos", ")", ")", "!==", "false", ")", "{", "if", "(", "$", "pos", "==", "0", "||", "$", "text", "[", "$", "pos", "-", "1", "]", "==", "' '", ")", "{", "$", "copy", "=", "substr_replace", "(", "$", "copy", ",", "$", "nbsp", ",", "$", "pos", "+", "$", "diff", ",", "1", ")", ";", "$", "diff", "+=", "$", "len", "-", "1", ";", "}", "$", "pos", "++", ";", "}", "$", "text", "=", "$", "copy", ";", "}", "// make the whole line non-breakable if needed", "else", "if", "(", "$", "text", "!==", "''", "&&", "preg_match", "(", "'/[^a-zA-Z0-9_]/'", ",", "$", "text", ")", ")", "{", "// use non-breakable spaces to correctly display", "// trailing/leading spaces and multi-space inside", "$", "text", "=", "str_replace", "(", "' '", ",", "$", "nbsp", ",", "$", "text", ")", ";", "// wrap in nobr element, so it's not wrapped on e.g. - or /", "$", "text", "=", "$", "this", "->", "config", "[", "'nobr_start'", "]", ".", "$", "text", ".", "$", "this", "->", "config", "[", "'nobr_end'", "]", ";", "}", "return", "$", "text", ";", "}" ]
Converts spaces in line of text
[ "Converts", "spaces", "in", "line", "of", "text" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_text2html.php#L269-L319
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_mime.php
rcube_mime.parse_message
public static function parse_message($raw_body) { $conf = array( 'include_bodies' => true, 'decode_bodies' => true, 'decode_headers' => false, 'default_charset' => self::get_charset(), ); $mime = new rcube_mime_decode($conf); return $mime->decode($raw_body); }
php
public static function parse_message($raw_body) { $conf = array( 'include_bodies' => true, 'decode_bodies' => true, 'decode_headers' => false, 'default_charset' => self::get_charset(), ); $mime = new rcube_mime_decode($conf); return $mime->decode($raw_body); }
[ "public", "static", "function", "parse_message", "(", "$", "raw_body", ")", "{", "$", "conf", "=", "array", "(", "'include_bodies'", "=>", "true", ",", "'decode_bodies'", "=>", "true", ",", "'decode_headers'", "=>", "false", ",", "'default_charset'", "=>", "self", "::", "get_charset", "(", ")", ",", ")", ";", "$", "mime", "=", "new", "rcube_mime_decode", "(", "$", "conf", ")", ";", "return", "$", "mime", "->", "decode", "(", "$", "raw_body", ")", ";", "}" ]
Parse the given raw message source and return a structure of rcube_message_part objects. It makes use of the rcube_mime_decode library @param string $raw_body The message source @return object rcube_message_part The message structure
[ "Parse", "the", "given", "raw", "message", "source", "and", "return", "a", "structure", "of", "rcube_message_part", "objects", "." ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_mime.php#L70-L82
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_mime.php
rcube_mime.decode_address_list
static function decode_address_list($input, $max = null, $decode = true, $fallback = null, $addronly = false) { $a = self::parse_address_list($input, $decode, $fallback); $out = array(); $j = 0; // Special chars as defined by RFC 822 need to in quoted string (or escaped). $special_chars = '[\(\)\<\>\\\.\[\]@,;:"]'; if (!is_array($a)) { return $out; } foreach ($a as $val) { $j++; $address = trim($val['address']); if ($addronly) { $out[$j] = $address; } else { $name = trim($val['name']); if ($name && $address && $name != $address) $string = sprintf('%s <%s>', preg_match("/$special_chars/", $name) ? '"'.addcslashes($name, '"').'"' : $name, $address); else if ($address) $string = $address; else if ($name) $string = $name; $out[$j] = array('name' => $name, 'mailto' => $address, 'string' => $string); } if ($max && $j==$max) break; } return $out; }
php
static function decode_address_list($input, $max = null, $decode = true, $fallback = null, $addronly = false) { $a = self::parse_address_list($input, $decode, $fallback); $out = array(); $j = 0; // Special chars as defined by RFC 822 need to in quoted string (or escaped). $special_chars = '[\(\)\<\>\\\.\[\]@,;:"]'; if (!is_array($a)) { return $out; } foreach ($a as $val) { $j++; $address = trim($val['address']); if ($addronly) { $out[$j] = $address; } else { $name = trim($val['name']); if ($name && $address && $name != $address) $string = sprintf('%s <%s>', preg_match("/$special_chars/", $name) ? '"'.addcslashes($name, '"').'"' : $name, $address); else if ($address) $string = $address; else if ($name) $string = $name; $out[$j] = array('name' => $name, 'mailto' => $address, 'string' => $string); } if ($max && $j==$max) break; } return $out; }
[ "static", "function", "decode_address_list", "(", "$", "input", ",", "$", "max", "=", "null", ",", "$", "decode", "=", "true", ",", "$", "fallback", "=", "null", ",", "$", "addronly", "=", "false", ")", "{", "$", "a", "=", "self", "::", "parse_address_list", "(", "$", "input", ",", "$", "decode", ",", "$", "fallback", ")", ";", "$", "out", "=", "array", "(", ")", ";", "$", "j", "=", "0", ";", "// Special chars as defined by RFC 822 need to in quoted string (or escaped).", "$", "special_chars", "=", "'[\\(\\)\\<\\>\\\\\\.\\[\\]@,;:\"]'", ";", "if", "(", "!", "is_array", "(", "$", "a", ")", ")", "{", "return", "$", "out", ";", "}", "foreach", "(", "$", "a", "as", "$", "val", ")", "{", "$", "j", "++", ";", "$", "address", "=", "trim", "(", "$", "val", "[", "'address'", "]", ")", ";", "if", "(", "$", "addronly", ")", "{", "$", "out", "[", "$", "j", "]", "=", "$", "address", ";", "}", "else", "{", "$", "name", "=", "trim", "(", "$", "val", "[", "'name'", "]", ")", ";", "if", "(", "$", "name", "&&", "$", "address", "&&", "$", "name", "!=", "$", "address", ")", "$", "string", "=", "sprintf", "(", "'%s <%s>'", ",", "preg_match", "(", "\"/$special_chars/\"", ",", "$", "name", ")", "?", "'\"'", ".", "addcslashes", "(", "$", "name", ",", "'\"'", ")", ".", "'\"'", ":", "$", "name", ",", "$", "address", ")", ";", "else", "if", "(", "$", "address", ")", "$", "string", "=", "$", "address", ";", "else", "if", "(", "$", "name", ")", "$", "string", "=", "$", "name", ";", "$", "out", "[", "$", "j", "]", "=", "array", "(", "'name'", "=>", "$", "name", ",", "'mailto'", "=>", "$", "address", ",", "'string'", "=>", "$", "string", ")", ";", "}", "if", "(", "$", "max", "&&", "$", "j", "==", "$", "max", ")", "break", ";", "}", "return", "$", "out", ";", "}" ]
Split an address list into a structured array list @param string $input Input string @param int $max List only this number of addresses @param boolean $decode Decode address strings @param string $fallback Fallback charset if none specified @param boolean $addronly Return flat array with e-mail addresses only @return array Indexed list of addresses
[ "Split", "an", "address", "list", "into", "a", "structured", "array", "list" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_mime.php#L95-L132
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_mime.php
rcube_mime.decode_header
public static function decode_header($input, $fallback = null) { $str = self::decode_mime_string((string)$input, $fallback); return $str; }
php
public static function decode_header($input, $fallback = null) { $str = self::decode_mime_string((string)$input, $fallback); return $str; }
[ "public", "static", "function", "decode_header", "(", "$", "input", ",", "$", "fallback", "=", "null", ")", "{", "$", "str", "=", "self", "::", "decode_mime_string", "(", "(", "string", ")", "$", "input", ",", "$", "fallback", ")", ";", "return", "$", "str", ";", "}" ]
Decode a message header value @param string $input Header value @param string $fallback Fallback charset if none specified @return string Decoded string
[ "Decode", "a", "message", "header", "value" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_mime.php#L142-L147
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_mime.php
rcube_mime.decode
public static function decode($input, $encoding = '7bit') { switch (strtolower($encoding)) { case 'quoted-printable': return quoted_printable_decode($input); case 'base64': return base64_decode($input); case 'x-uuencode': case 'x-uue': case 'uue': case 'uuencode': return convert_uudecode($input); case '7bit': default: return $input; } }
php
public static function decode($input, $encoding = '7bit') { switch (strtolower($encoding)) { case 'quoted-printable': return quoted_printable_decode($input); case 'base64': return base64_decode($input); case 'x-uuencode': case 'x-uue': case 'uue': case 'uuencode': return convert_uudecode($input); case '7bit': default: return $input; } }
[ "public", "static", "function", "decode", "(", "$", "input", ",", "$", "encoding", "=", "'7bit'", ")", "{", "switch", "(", "strtolower", "(", "$", "encoding", ")", ")", "{", "case", "'quoted-printable'", ":", "return", "quoted_printable_decode", "(", "$", "input", ")", ";", "case", "'base64'", ":", "return", "base64_decode", "(", "$", "input", ")", ";", "case", "'x-uuencode'", ":", "case", "'x-uue'", ":", "case", "'uue'", ":", "case", "'uuencode'", ":", "return", "convert_uudecode", "(", "$", "input", ")", ";", "case", "'7bit'", ":", "default", ":", "return", "$", "input", ";", "}", "}" ]
Decode a mime part @param string $input Input string @param string $encoding Part encoding @return string Decoded string
[ "Decode", "a", "mime", "part" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_mime.php#L265-L281
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_mime.php
rcube_mime.parse_headers
public static function parse_headers($headers) { $a_headers = array(); $headers = preg_replace('/\r?\n(\t| )+/', ' ', $headers); $lines = explode("\n", $headers); $count = count($lines); for ($i=0; $i<$count; $i++) { if ($p = strpos($lines[$i], ': ')) { $field = strtolower(substr($lines[$i], 0, $p)); $value = trim(substr($lines[$i], $p+1)); if (!empty($value)) { $a_headers[$field] = $value; } } } return $a_headers; }
php
public static function parse_headers($headers) { $a_headers = array(); $headers = preg_replace('/\r?\n(\t| )+/', ' ', $headers); $lines = explode("\n", $headers); $count = count($lines); for ($i=0; $i<$count; $i++) { if ($p = strpos($lines[$i], ': ')) { $field = strtolower(substr($lines[$i], 0, $p)); $value = trim(substr($lines[$i], $p+1)); if (!empty($value)) { $a_headers[$field] = $value; } } } return $a_headers; }
[ "public", "static", "function", "parse_headers", "(", "$", "headers", ")", "{", "$", "a_headers", "=", "array", "(", ")", ";", "$", "headers", "=", "preg_replace", "(", "'/\\r?\\n(\\t| )+/'", ",", "' '", ",", "$", "headers", ")", ";", "$", "lines", "=", "explode", "(", "\"\\n\"", ",", "$", "headers", ")", ";", "$", "count", "=", "count", "(", "$", "lines", ")", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "count", ";", "$", "i", "++", ")", "{", "if", "(", "$", "p", "=", "strpos", "(", "$", "lines", "[", "$", "i", "]", ",", "': '", ")", ")", "{", "$", "field", "=", "strtolower", "(", "substr", "(", "$", "lines", "[", "$", "i", "]", ",", "0", ",", "$", "p", ")", ")", ";", "$", "value", "=", "trim", "(", "substr", "(", "$", "lines", "[", "$", "i", "]", ",", "$", "p", "+", "1", ")", ")", ";", "if", "(", "!", "empty", "(", "$", "value", ")", ")", "{", "$", "a_headers", "[", "$", "field", "]", "=", "$", "value", ";", "}", "}", "}", "return", "$", "a_headers", ";", "}" ]
Split RFC822 header string into an associative array
[ "Split", "RFC822", "header", "string", "into", "an", "associative", "array" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_mime.php#L286-L304
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_mime.php
rcube_mime.parse_address_list
private static function parse_address_list($str, $decode = true, $fallback = null) { // remove any newlines and carriage returns before $str = preg_replace('/\r?\n(\s|\t)?/', ' ', $str); // extract list items, remove comments $str = self::explode_header_string(',;', $str, true); $result = array(); // simplified regexp, supporting quoted local part $email_rx = '(\S+|("\s*(?:[^"\f\n\r\t\v\b\s]+\s*)+"))@\S+'; foreach ($str as $key => $val) { $name = ''; $address = ''; $val = trim($val); if (preg_match('/(.*)<('.$email_rx.')>$/', $val, $m)) { $address = $m[2]; $name = trim($m[1]); } else if (preg_match('/^('.$email_rx.')$/', $val, $m)) { $address = $m[1]; $name = ''; } // special case (#1489092) else if (preg_match('/(\s*<MAILER-DAEMON>)$/', $val, $m)) { $address = 'MAILER-DAEMON'; $name = substr($val, 0, -strlen($m[1])); } else if (preg_match('/('.$email_rx.')/', $val, $m)) { $name = $m[1]; } else { $name = $val; } // dequote and/or decode name if ($name) { if ($name[0] == '"' && $name[strlen($name)-1] == '"') { $name = substr($name, 1, -1); $name = stripslashes($name); } if ($decode) { $name = self::decode_header($name, $fallback); // some clients encode addressee name with quotes around it if ($name[0] == '"' && $name[strlen($name)-1] == '"') { $name = substr($name, 1, -1); } } } if (!$address && $name) { $address = $name; $name = ''; } if ($address) { $address = self::fix_email($address); $result[$key] = array('name' => $name, 'address' => $address); } } return $result; }
php
private static function parse_address_list($str, $decode = true, $fallback = null) { // remove any newlines and carriage returns before $str = preg_replace('/\r?\n(\s|\t)?/', ' ', $str); // extract list items, remove comments $str = self::explode_header_string(',;', $str, true); $result = array(); // simplified regexp, supporting quoted local part $email_rx = '(\S+|("\s*(?:[^"\f\n\r\t\v\b\s]+\s*)+"))@\S+'; foreach ($str as $key => $val) { $name = ''; $address = ''; $val = trim($val); if (preg_match('/(.*)<('.$email_rx.')>$/', $val, $m)) { $address = $m[2]; $name = trim($m[1]); } else if (preg_match('/^('.$email_rx.')$/', $val, $m)) { $address = $m[1]; $name = ''; } // special case (#1489092) else if (preg_match('/(\s*<MAILER-DAEMON>)$/', $val, $m)) { $address = 'MAILER-DAEMON'; $name = substr($val, 0, -strlen($m[1])); } else if (preg_match('/('.$email_rx.')/', $val, $m)) { $name = $m[1]; } else { $name = $val; } // dequote and/or decode name if ($name) { if ($name[0] == '"' && $name[strlen($name)-1] == '"') { $name = substr($name, 1, -1); $name = stripslashes($name); } if ($decode) { $name = self::decode_header($name, $fallback); // some clients encode addressee name with quotes around it if ($name[0] == '"' && $name[strlen($name)-1] == '"') { $name = substr($name, 1, -1); } } } if (!$address && $name) { $address = $name; $name = ''; } if ($address) { $address = self::fix_email($address); $result[$key] = array('name' => $name, 'address' => $address); } } return $result; }
[ "private", "static", "function", "parse_address_list", "(", "$", "str", ",", "$", "decode", "=", "true", ",", "$", "fallback", "=", "null", ")", "{", "// remove any newlines and carriage returns before", "$", "str", "=", "preg_replace", "(", "'/\\r?\\n(\\s|\\t)?/'", ",", "' '", ",", "$", "str", ")", ";", "// extract list items, remove comments", "$", "str", "=", "self", "::", "explode_header_string", "(", "',;'", ",", "$", "str", ",", "true", ")", ";", "$", "result", "=", "array", "(", ")", ";", "// simplified regexp, supporting quoted local part", "$", "email_rx", "=", "'(\\S+|(\"\\s*(?:[^\"\\f\\n\\r\\t\\v\\b\\s]+\\s*)+\"))@\\S+'", ";", "foreach", "(", "$", "str", "as", "$", "key", "=>", "$", "val", ")", "{", "$", "name", "=", "''", ";", "$", "address", "=", "''", ";", "$", "val", "=", "trim", "(", "$", "val", ")", ";", "if", "(", "preg_match", "(", "'/(.*)<('", ".", "$", "email_rx", ".", "')>$/'", ",", "$", "val", ",", "$", "m", ")", ")", "{", "$", "address", "=", "$", "m", "[", "2", "]", ";", "$", "name", "=", "trim", "(", "$", "m", "[", "1", "]", ")", ";", "}", "else", "if", "(", "preg_match", "(", "'/^('", ".", "$", "email_rx", ".", "')$/'", ",", "$", "val", ",", "$", "m", ")", ")", "{", "$", "address", "=", "$", "m", "[", "1", "]", ";", "$", "name", "=", "''", ";", "}", "// special case (#1489092)", "else", "if", "(", "preg_match", "(", "'/(\\s*<MAILER-DAEMON>)$/'", ",", "$", "val", ",", "$", "m", ")", ")", "{", "$", "address", "=", "'MAILER-DAEMON'", ";", "$", "name", "=", "substr", "(", "$", "val", ",", "0", ",", "-", "strlen", "(", "$", "m", "[", "1", "]", ")", ")", ";", "}", "else", "if", "(", "preg_match", "(", "'/('", ".", "$", "email_rx", ".", "')/'", ",", "$", "val", ",", "$", "m", ")", ")", "{", "$", "name", "=", "$", "m", "[", "1", "]", ";", "}", "else", "{", "$", "name", "=", "$", "val", ";", "}", "// dequote and/or decode name", "if", "(", "$", "name", ")", "{", "if", "(", "$", "name", "[", "0", "]", "==", "'\"'", "&&", "$", "name", "[", "strlen", "(", "$", "name", ")", "-", "1", "]", "==", "'\"'", ")", "{", "$", "name", "=", "substr", "(", "$", "name", ",", "1", ",", "-", "1", ")", ";", "$", "name", "=", "stripslashes", "(", "$", "name", ")", ";", "}", "if", "(", "$", "decode", ")", "{", "$", "name", "=", "self", "::", "decode_header", "(", "$", "name", ",", "$", "fallback", ")", ";", "// some clients encode addressee name with quotes around it", "if", "(", "$", "name", "[", "0", "]", "==", "'\"'", "&&", "$", "name", "[", "strlen", "(", "$", "name", ")", "-", "1", "]", "==", "'\"'", ")", "{", "$", "name", "=", "substr", "(", "$", "name", ",", "1", ",", "-", "1", ")", ";", "}", "}", "}", "if", "(", "!", "$", "address", "&&", "$", "name", ")", "{", "$", "address", "=", "$", "name", ";", "$", "name", "=", "''", ";", "}", "if", "(", "$", "address", ")", "{", "$", "address", "=", "self", "::", "fix_email", "(", "$", "address", ")", ";", "$", "result", "[", "$", "key", "]", "=", "array", "(", "'name'", "=>", "$", "name", ",", "'address'", "=>", "$", "address", ")", ";", "}", "}", "return", "$", "result", ";", "}" ]
E-mail address list parser
[ "E", "-", "mail", "address", "list", "parser" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_mime.php#L309-L373
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_mime.php
rcube_mime.unfold_flowed
public static function unfold_flowed($text, $mark = null, $delsp = false) { $text = preg_split('/\r?\n/', $text); $last = -1; $q_level = 0; $marks = array(); foreach ($text as $idx => $line) { if ($q = strspn($line, '>')) { // remove quote chars $line = substr($line, $q); // remove (optional) space-staffing if ($line[0] === ' ') $line = substr($line, 1); // The same paragraph (We join current line with the previous one) when: // - the same level of quoting // - previous line was flowed // - previous line contains more than only one single space (and quote char(s)) if ($q == $q_level && isset($text[$last]) && $text[$last][strlen($text[$last])-1] == ' ' && !preg_match('/^>+ {0,1}$/', $text[$last]) ) { if ($delsp) { $text[$last] = substr($text[$last], 0, -1); } $text[$last] .= $line; unset($text[$idx]); if ($mark) { $marks[$last] = true; } } else { $last = $idx; } } else { if ($line == '-- ') { $last = $idx; } else { // remove space-stuffing if ($line[0] === ' ') $line = substr($line, 1); if (isset($text[$last]) && $line && !$q_level && $text[$last] != '-- ' && $text[$last][strlen($text[$last])-1] == ' ' ) { if ($delsp) { $text[$last] = substr($text[$last], 0, -1); } $text[$last] .= $line; unset($text[$idx]); if ($mark) { $marks[$last] = true; } } else { $text[$idx] = $line; $last = $idx; } } } $q_level = $q; } if (!empty($marks)) { foreach (array_keys($marks) as $mk) { $text[$mk] = $mark . $text[$mk]; } } return implode("\r\n", $text); }
php
public static function unfold_flowed($text, $mark = null, $delsp = false) { $text = preg_split('/\r?\n/', $text); $last = -1; $q_level = 0; $marks = array(); foreach ($text as $idx => $line) { if ($q = strspn($line, '>')) { // remove quote chars $line = substr($line, $q); // remove (optional) space-staffing if ($line[0] === ' ') $line = substr($line, 1); // The same paragraph (We join current line with the previous one) when: // - the same level of quoting // - previous line was flowed // - previous line contains more than only one single space (and quote char(s)) if ($q == $q_level && isset($text[$last]) && $text[$last][strlen($text[$last])-1] == ' ' && !preg_match('/^>+ {0,1}$/', $text[$last]) ) { if ($delsp) { $text[$last] = substr($text[$last], 0, -1); } $text[$last] .= $line; unset($text[$idx]); if ($mark) { $marks[$last] = true; } } else { $last = $idx; } } else { if ($line == '-- ') { $last = $idx; } else { // remove space-stuffing if ($line[0] === ' ') $line = substr($line, 1); if (isset($text[$last]) && $line && !$q_level && $text[$last] != '-- ' && $text[$last][strlen($text[$last])-1] == ' ' ) { if ($delsp) { $text[$last] = substr($text[$last], 0, -1); } $text[$last] .= $line; unset($text[$idx]); if ($mark) { $marks[$last] = true; } } else { $text[$idx] = $line; $last = $idx; } } } $q_level = $q; } if (!empty($marks)) { foreach (array_keys($marks) as $mk) { $text[$mk] = $mark . $text[$mk]; } } return implode("\r\n", $text); }
[ "public", "static", "function", "unfold_flowed", "(", "$", "text", ",", "$", "mark", "=", "null", ",", "$", "delsp", "=", "false", ")", "{", "$", "text", "=", "preg_split", "(", "'/\\r?\\n/'", ",", "$", "text", ")", ";", "$", "last", "=", "-", "1", ";", "$", "q_level", "=", "0", ";", "$", "marks", "=", "array", "(", ")", ";", "foreach", "(", "$", "text", "as", "$", "idx", "=>", "$", "line", ")", "{", "if", "(", "$", "q", "=", "strspn", "(", "$", "line", ",", "'>'", ")", ")", "{", "// remove quote chars", "$", "line", "=", "substr", "(", "$", "line", ",", "$", "q", ")", ";", "// remove (optional) space-staffing", "if", "(", "$", "line", "[", "0", "]", "===", "' '", ")", "$", "line", "=", "substr", "(", "$", "line", ",", "1", ")", ";", "// The same paragraph (We join current line with the previous one) when:", "// - the same level of quoting", "// - previous line was flowed", "// - previous line contains more than only one single space (and quote char(s))", "if", "(", "$", "q", "==", "$", "q_level", "&&", "isset", "(", "$", "text", "[", "$", "last", "]", ")", "&&", "$", "text", "[", "$", "last", "]", "[", "strlen", "(", "$", "text", "[", "$", "last", "]", ")", "-", "1", "]", "==", "' '", "&&", "!", "preg_match", "(", "'/^>+ {0,1}$/'", ",", "$", "text", "[", "$", "last", "]", ")", ")", "{", "if", "(", "$", "delsp", ")", "{", "$", "text", "[", "$", "last", "]", "=", "substr", "(", "$", "text", "[", "$", "last", "]", ",", "0", ",", "-", "1", ")", ";", "}", "$", "text", "[", "$", "last", "]", ".=", "$", "line", ";", "unset", "(", "$", "text", "[", "$", "idx", "]", ")", ";", "if", "(", "$", "mark", ")", "{", "$", "marks", "[", "$", "last", "]", "=", "true", ";", "}", "}", "else", "{", "$", "last", "=", "$", "idx", ";", "}", "}", "else", "{", "if", "(", "$", "line", "==", "'-- '", ")", "{", "$", "last", "=", "$", "idx", ";", "}", "else", "{", "// remove space-stuffing", "if", "(", "$", "line", "[", "0", "]", "===", "' '", ")", "$", "line", "=", "substr", "(", "$", "line", ",", "1", ")", ";", "if", "(", "isset", "(", "$", "text", "[", "$", "last", "]", ")", "&&", "$", "line", "&&", "!", "$", "q_level", "&&", "$", "text", "[", "$", "last", "]", "!=", "'-- '", "&&", "$", "text", "[", "$", "last", "]", "[", "strlen", "(", "$", "text", "[", "$", "last", "]", ")", "-", "1", "]", "==", "' '", ")", "{", "if", "(", "$", "delsp", ")", "{", "$", "text", "[", "$", "last", "]", "=", "substr", "(", "$", "text", "[", "$", "last", "]", ",", "0", ",", "-", "1", ")", ";", "}", "$", "text", "[", "$", "last", "]", ".=", "$", "line", ";", "unset", "(", "$", "text", "[", "$", "idx", "]", ")", ";", "if", "(", "$", "mark", ")", "{", "$", "marks", "[", "$", "last", "]", "=", "true", ";", "}", "}", "else", "{", "$", "text", "[", "$", "idx", "]", "=", "$", "line", ";", "$", "last", "=", "$", "idx", ";", "}", "}", "}", "$", "q_level", "=", "$", "q", ";", "}", "if", "(", "!", "empty", "(", "$", "marks", ")", ")", "{", "foreach", "(", "array_keys", "(", "$", "marks", ")", "as", "$", "mk", ")", "{", "$", "text", "[", "$", "mk", "]", "=", "$", "mark", ".", "$", "text", "[", "$", "mk", "]", ";", "}", "}", "return", "implode", "(", "\"\\r\\n\"", ",", "$", "text", ")", ";", "}" ]
Interpret a format=flowed message body according to RFC 2646 @param string $text Raw body formatted as flowed text @param string $mark Mark each flowed line with specified character @param boolean $delsp Remove the trailing space of each flowed line @return string Interpreted text with unwrapped lines and stuffed space removed
[ "Interpret", "a", "format", "=", "flowed", "message", "body", "according", "to", "RFC", "2646" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_mime.php#L458-L532
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_mime.php
rcube_mime.format_flowed
public static function format_flowed($text, $length = 72, $charset=null) { $text = preg_split('/\r?\n/', $text); foreach ($text as $idx => $line) { if ($line != '-- ') { if ($level = strspn($line, '>')) { // remove quote chars $line = substr($line, $level); // remove (optional) space-staffing and spaces before the line end $line = rtrim($line, ' '); if ($line[0] === ' ') $line = substr($line, 1); $prefix = str_repeat('>', $level) . ' '; $line = $prefix . self::wordwrap($line, $length - $level - 2, " \r\n$prefix", false, $charset); } else if ($line) { $line = self::wordwrap(rtrim($line), $length - 2, " \r\n", false, $charset); // space-stuffing $line = preg_replace('/(^|\r\n)(From| |>)/', '\\1 \\2', $line); } $text[$idx] = $line; } } return implode("\r\n", $text); }
php
public static function format_flowed($text, $length = 72, $charset=null) { $text = preg_split('/\r?\n/', $text); foreach ($text as $idx => $line) { if ($line != '-- ') { if ($level = strspn($line, '>')) { // remove quote chars $line = substr($line, $level); // remove (optional) space-staffing and spaces before the line end $line = rtrim($line, ' '); if ($line[0] === ' ') $line = substr($line, 1); $prefix = str_repeat('>', $level) . ' '; $line = $prefix . self::wordwrap($line, $length - $level - 2, " \r\n$prefix", false, $charset); } else if ($line) { $line = self::wordwrap(rtrim($line), $length - 2, " \r\n", false, $charset); // space-stuffing $line = preg_replace('/(^|\r\n)(From| |>)/', '\\1 \\2', $line); } $text[$idx] = $line; } } return implode("\r\n", $text); }
[ "public", "static", "function", "format_flowed", "(", "$", "text", ",", "$", "length", "=", "72", ",", "$", "charset", "=", "null", ")", "{", "$", "text", "=", "preg_split", "(", "'/\\r?\\n/'", ",", "$", "text", ")", ";", "foreach", "(", "$", "text", "as", "$", "idx", "=>", "$", "line", ")", "{", "if", "(", "$", "line", "!=", "'-- '", ")", "{", "if", "(", "$", "level", "=", "strspn", "(", "$", "line", ",", "'>'", ")", ")", "{", "// remove quote chars", "$", "line", "=", "substr", "(", "$", "line", ",", "$", "level", ")", ";", "// remove (optional) space-staffing and spaces before the line end", "$", "line", "=", "rtrim", "(", "$", "line", ",", "' '", ")", ";", "if", "(", "$", "line", "[", "0", "]", "===", "' '", ")", "$", "line", "=", "substr", "(", "$", "line", ",", "1", ")", ";", "$", "prefix", "=", "str_repeat", "(", "'>'", ",", "$", "level", ")", ".", "' '", ";", "$", "line", "=", "$", "prefix", ".", "self", "::", "wordwrap", "(", "$", "line", ",", "$", "length", "-", "$", "level", "-", "2", ",", "\" \\r\\n$prefix\"", ",", "false", ",", "$", "charset", ")", ";", "}", "else", "if", "(", "$", "line", ")", "{", "$", "line", "=", "self", "::", "wordwrap", "(", "rtrim", "(", "$", "line", ")", ",", "$", "length", "-", "2", ",", "\" \\r\\n\"", ",", "false", ",", "$", "charset", ")", ";", "// space-stuffing", "$", "line", "=", "preg_replace", "(", "'/(^|\\r\\n)(From| |>)/'", ",", "'\\\\1 \\\\2'", ",", "$", "line", ")", ";", "}", "$", "text", "[", "$", "idx", "]", "=", "$", "line", ";", "}", "}", "return", "implode", "(", "\"\\r\\n\"", ",", "$", "text", ")", ";", "}" ]
Wrap the given text to comply with RFC 2646 @param string $text Text to wrap @param int $length Length @param string $charset Character encoding of $text @return string Wrapped text
[ "Wrap", "the", "given", "text", "to", "comply", "with", "RFC", "2646" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_mime.php#L543-L570
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_mime.php
rcube_mime.file_content_type
public static function file_content_type($path, $name, $failover = 'application/octet-stream', $is_stream = false, $skip_suffix = false) { static $mime_ext = array(); $mime_type = null; $config = rcube::get_instance()->config; $mime_magic = $config->get('mime_magic'); if (!$skip_suffix && empty($mime_ext)) { foreach ($config->resolve_paths('mimetypes.php') as $fpath) { $mime_ext = array_merge($mime_ext, (array) @include($fpath)); } } // use file name suffix with hard-coded mime-type map if (!$skip_suffix && is_array($mime_ext) && $name) { if ($suffix = substr($name, strrpos($name, '.')+1)) { $mime_type = $mime_ext[strtolower($suffix)]; } } // try fileinfo extension if available if (!$mime_type && function_exists('finfo_open')) { // null as a 2nd argument should be the same as no argument // this however is not true on all systems/versions if ($mime_magic) { $finfo = finfo_open(FILEINFO_MIME, $mime_magic); } else { $finfo = finfo_open(FILEINFO_MIME); } if ($finfo) { if ($is_stream) $mime_type = finfo_buffer($finfo, $path); else $mime_type = finfo_file($finfo, $path); finfo_close($finfo); } } // try PHP's mime_content_type if (!$mime_type && !$is_stream && function_exists('mime_content_type')) { $mime_type = @mime_content_type($path); } // fall back to user-submitted string if (!$mime_type) { $mime_type = $failover; } else { // Sometimes (PHP-5.3?) content-type contains charset definition, // Remove it (#1487122) also "charset=binary" is useless $mime_type = array_shift(preg_split('/[; ]/', $mime_type)); } return $mime_type; }
php
public static function file_content_type($path, $name, $failover = 'application/octet-stream', $is_stream = false, $skip_suffix = false) { static $mime_ext = array(); $mime_type = null; $config = rcube::get_instance()->config; $mime_magic = $config->get('mime_magic'); if (!$skip_suffix && empty($mime_ext)) { foreach ($config->resolve_paths('mimetypes.php') as $fpath) { $mime_ext = array_merge($mime_ext, (array) @include($fpath)); } } // use file name suffix with hard-coded mime-type map if (!$skip_suffix && is_array($mime_ext) && $name) { if ($suffix = substr($name, strrpos($name, '.')+1)) { $mime_type = $mime_ext[strtolower($suffix)]; } } // try fileinfo extension if available if (!$mime_type && function_exists('finfo_open')) { // null as a 2nd argument should be the same as no argument // this however is not true on all systems/versions if ($mime_magic) { $finfo = finfo_open(FILEINFO_MIME, $mime_magic); } else { $finfo = finfo_open(FILEINFO_MIME); } if ($finfo) { if ($is_stream) $mime_type = finfo_buffer($finfo, $path); else $mime_type = finfo_file($finfo, $path); finfo_close($finfo); } } // try PHP's mime_content_type if (!$mime_type && !$is_stream && function_exists('mime_content_type')) { $mime_type = @mime_content_type($path); } // fall back to user-submitted string if (!$mime_type) { $mime_type = $failover; } else { // Sometimes (PHP-5.3?) content-type contains charset definition, // Remove it (#1487122) also "charset=binary" is useless $mime_type = array_shift(preg_split('/[; ]/', $mime_type)); } return $mime_type; }
[ "public", "static", "function", "file_content_type", "(", "$", "path", ",", "$", "name", ",", "$", "failover", "=", "'application/octet-stream'", ",", "$", "is_stream", "=", "false", ",", "$", "skip_suffix", "=", "false", ")", "{", "static", "$", "mime_ext", "=", "array", "(", ")", ";", "$", "mime_type", "=", "null", ";", "$", "config", "=", "rcube", "::", "get_instance", "(", ")", "->", "config", ";", "$", "mime_magic", "=", "$", "config", "->", "get", "(", "'mime_magic'", ")", ";", "if", "(", "!", "$", "skip_suffix", "&&", "empty", "(", "$", "mime_ext", ")", ")", "{", "foreach", "(", "$", "config", "->", "resolve_paths", "(", "'mimetypes.php'", ")", "as", "$", "fpath", ")", "{", "$", "mime_ext", "=", "array_merge", "(", "$", "mime_ext", ",", "(", "array", ")", "@", "include", "(", "$", "fpath", ")", ")", ";", "}", "}", "// use file name suffix with hard-coded mime-type map", "if", "(", "!", "$", "skip_suffix", "&&", "is_array", "(", "$", "mime_ext", ")", "&&", "$", "name", ")", "{", "if", "(", "$", "suffix", "=", "substr", "(", "$", "name", ",", "strrpos", "(", "$", "name", ",", "'.'", ")", "+", "1", ")", ")", "{", "$", "mime_type", "=", "$", "mime_ext", "[", "strtolower", "(", "$", "suffix", ")", "]", ";", "}", "}", "// try fileinfo extension if available", "if", "(", "!", "$", "mime_type", "&&", "function_exists", "(", "'finfo_open'", ")", ")", "{", "// null as a 2nd argument should be the same as no argument", "// this however is not true on all systems/versions", "if", "(", "$", "mime_magic", ")", "{", "$", "finfo", "=", "finfo_open", "(", "FILEINFO_MIME", ",", "$", "mime_magic", ")", ";", "}", "else", "{", "$", "finfo", "=", "finfo_open", "(", "FILEINFO_MIME", ")", ";", "}", "if", "(", "$", "finfo", ")", "{", "if", "(", "$", "is_stream", ")", "$", "mime_type", "=", "finfo_buffer", "(", "$", "finfo", ",", "$", "path", ")", ";", "else", "$", "mime_type", "=", "finfo_file", "(", "$", "finfo", ",", "$", "path", ")", ";", "finfo_close", "(", "$", "finfo", ")", ";", "}", "}", "// try PHP's mime_content_type", "if", "(", "!", "$", "mime_type", "&&", "!", "$", "is_stream", "&&", "function_exists", "(", "'mime_content_type'", ")", ")", "{", "$", "mime_type", "=", "@", "mime_content_type", "(", "$", "path", ")", ";", "}", "// fall back to user-submitted string", "if", "(", "!", "$", "mime_type", ")", "{", "$", "mime_type", "=", "$", "failover", ";", "}", "else", "{", "// Sometimes (PHP-5.3?) content-type contains charset definition,", "// Remove it (#1487122) also \"charset=binary\" is useless", "$", "mime_type", "=", "array_shift", "(", "preg_split", "(", "'/[; ]/'", ",", "$", "mime_type", ")", ")", ";", "}", "return", "$", "mime_type", ";", "}" ]
A method to guess the mime_type of an attachment. @param string $path Path to the file or file contents @param string $name File name (with suffix) @param string $failover Mime type supplied for failover @param boolean $is_stream Set to True if $path contains file contents @param boolean $skip_suffix Set to True if the config/mimetypes.php mappig should be ignored @return string @author Till Klampaeckel <[email protected]> @see http://de2.php.net/manual/en/ref.fileinfo.php @see http://de2.php.net/mime_content_type
[ "A", "method", "to", "guess", "the", "mime_type", "of", "an", "attachment", "." ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_mime.php#L705-L762
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_mime.php
rcube_mime.image_content_type
public static function image_content_type($data) { $type = 'jpeg'; if (preg_match('/^\x89\x50\x4E\x47/', $data)) $type = 'png'; else if (preg_match('/^\x47\x49\x46\x38/', $data)) $type = 'gif'; else if (preg_match('/^\x00\x00\x01\x00/', $data)) $type = 'ico'; // else if (preg_match('/^\xFF\xD8\xFF\xE0/', $data)) $type = 'jpeg'; return 'image/' . $type; }
php
public static function image_content_type($data) { $type = 'jpeg'; if (preg_match('/^\x89\x50\x4E\x47/', $data)) $type = 'png'; else if (preg_match('/^\x47\x49\x46\x38/', $data)) $type = 'gif'; else if (preg_match('/^\x00\x00\x01\x00/', $data)) $type = 'ico'; // else if (preg_match('/^\xFF\xD8\xFF\xE0/', $data)) $type = 'jpeg'; return 'image/' . $type; }
[ "public", "static", "function", "image_content_type", "(", "$", "data", ")", "{", "$", "type", "=", "'jpeg'", ";", "if", "(", "preg_match", "(", "'/^\\x89\\x50\\x4E\\x47/'", ",", "$", "data", ")", ")", "$", "type", "=", "'png'", ";", "else", "if", "(", "preg_match", "(", "'/^\\x47\\x49\\x46\\x38/'", ",", "$", "data", ")", ")", "$", "type", "=", "'gif'", ";", "else", "if", "(", "preg_match", "(", "'/^\\x00\\x00\\x01\\x00/'", ",", "$", "data", ")", ")", "$", "type", "=", "'ico'", ";", "// else if (preg_match('/^\\xFF\\xD8\\xFF\\xE0/', $data)) $type = 'jpeg';", "return", "'image/'", ".", "$", "type", ";", "}" ]
Detect image type of the given binary data by checking magic numbers. @param string $data Binary file content @return string Detected mime-type or jpeg as fallback
[ "Detect", "image", "type", "of", "the", "given", "binary", "data", "by", "checking", "magic", "numbers", "." ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_mime.php#L871-L880
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_mime.php
rcube_mime.fix_email
public static function fix_email($email) { $parts = rcube_utils::explode_quoted_string('@', $email); foreach ($parts as $idx => $part) { // remove redundant quoting (#1490040) if ($part[0] == '"' && preg_match('/^"([a-zA-Z0-9._+=-]+)"$/', $part, $m)) { $parts[$idx] = $m[1]; } } return implode('@', $parts); }
php
public static function fix_email($email) { $parts = rcube_utils::explode_quoted_string('@', $email); foreach ($parts as $idx => $part) { // remove redundant quoting (#1490040) if ($part[0] == '"' && preg_match('/^"([a-zA-Z0-9._+=-]+)"$/', $part, $m)) { $parts[$idx] = $m[1]; } } return implode('@', $parts); }
[ "public", "static", "function", "fix_email", "(", "$", "email", ")", "{", "$", "parts", "=", "rcube_utils", "::", "explode_quoted_string", "(", "'@'", ",", "$", "email", ")", ";", "foreach", "(", "$", "parts", "as", "$", "idx", "=>", "$", "part", ")", "{", "// remove redundant quoting (#1490040)", "if", "(", "$", "part", "[", "0", "]", "==", "'\"'", "&&", "preg_match", "(", "'/^\"([a-zA-Z0-9._+=-]+)\"$/'", ",", "$", "part", ",", "$", "m", ")", ")", "{", "$", "parts", "[", "$", "idx", "]", "=", "$", "m", "[", "1", "]", ";", "}", "}", "return", "implode", "(", "'@'", ",", "$", "parts", ")", ";", "}" ]
Try to fix invalid email addresses
[ "Try", "to", "fix", "invalid", "email", "addresses" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_mime.php#L885-L896
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_ldap.php
rcube_ldap.set_page
function set_page($page) { $this->list_page = (int)$page; $this->ldap->set_vlv_page($this->list_page, $this->page_size); }
php
function set_page($page) { $this->list_page = (int)$page; $this->ldap->set_vlv_page($this->list_page, $this->page_size); }
[ "function", "set_page", "(", "$", "page", ")", "{", "$", "this", "->", "list_page", "=", "(", "int", ")", "$", "page", ";", "$", "this", "->", "ldap", "->", "set_vlv_page", "(", "$", "this", "->", "list_page", ",", "$", "this", "->", "page_size", ")", ";", "}" ]
Set internal list page @param number Page number to list
[ "Set", "internal", "list", "page" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_ldap.php#L483-L487
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_ldap.php
rcube_ldap.set_pagesize
function set_pagesize($size) { $this->page_size = (int)$size; $this->ldap->set_vlv_page($this->list_page, $this->page_size); }
php
function set_pagesize($size) { $this->page_size = (int)$size; $this->ldap->set_vlv_page($this->list_page, $this->page_size); }
[ "function", "set_pagesize", "(", "$", "size", ")", "{", "$", "this", "->", "page_size", "=", "(", "int", ")", "$", "size", ";", "$", "this", "->", "ldap", "->", "set_vlv_page", "(", "$", "this", "->", "list_page", ",", "$", "this", "->", "page_size", ")", ";", "}" ]
Set internal page size @param number Number of records to display on one page
[ "Set", "internal", "page", "size" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_ldap.php#L494-L498
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_ldap.php
rcube_ldap.list_group_members
function list_group_members($dn, $count = false, $entries = null) { $group_members = array(); // fetch group object if (empty($entries)) { $attribs = array_merge(array('dn','objectClass','memberURL'), array_values($this->group_types)); $entries = $this->ldap->read_entries($dn, '(objectClass=*)', $attribs); if ($entries === false) { return $group_members; } } for ($i=0; $i < $entries['count']; $i++) { $entry = $entries[$i]; $attrs = array(); foreach ((array)$entry['objectclass'] as $objectclass) { if (($member_attr = $this->get_group_member_attr(array($objectclass), '')) && ($member_attr = strtolower($member_attr)) && !in_array($member_attr, $attrs) ) { $members = $this->_list_group_members($dn, $entry, $member_attr, $count); $group_members = array_merge($group_members, $members); $attrs[] = $member_attr; } else if (!empty($entry['memberurl'])) { $members = $this->_list_group_memberurl($dn, $entry, $count); $group_members = array_merge($group_members, $members); } if ($this->prop['sizelimit'] && count($group_members) > $this->prop['sizelimit']) { break 2; } } } return array_filter($group_members); }
php
function list_group_members($dn, $count = false, $entries = null) { $group_members = array(); // fetch group object if (empty($entries)) { $attribs = array_merge(array('dn','objectClass','memberURL'), array_values($this->group_types)); $entries = $this->ldap->read_entries($dn, '(objectClass=*)', $attribs); if ($entries === false) { return $group_members; } } for ($i=0; $i < $entries['count']; $i++) { $entry = $entries[$i]; $attrs = array(); foreach ((array)$entry['objectclass'] as $objectclass) { if (($member_attr = $this->get_group_member_attr(array($objectclass), '')) && ($member_attr = strtolower($member_attr)) && !in_array($member_attr, $attrs) ) { $members = $this->_list_group_members($dn, $entry, $member_attr, $count); $group_members = array_merge($group_members, $members); $attrs[] = $member_attr; } else if (!empty($entry['memberurl'])) { $members = $this->_list_group_memberurl($dn, $entry, $count); $group_members = array_merge($group_members, $members); } if ($this->prop['sizelimit'] && count($group_members) > $this->prop['sizelimit']) { break 2; } } } return array_filter($group_members); }
[ "function", "list_group_members", "(", "$", "dn", ",", "$", "count", "=", "false", ",", "$", "entries", "=", "null", ")", "{", "$", "group_members", "=", "array", "(", ")", ";", "// fetch group object", "if", "(", "empty", "(", "$", "entries", ")", ")", "{", "$", "attribs", "=", "array_merge", "(", "array", "(", "'dn'", ",", "'objectClass'", ",", "'memberURL'", ")", ",", "array_values", "(", "$", "this", "->", "group_types", ")", ")", ";", "$", "entries", "=", "$", "this", "->", "ldap", "->", "read_entries", "(", "$", "dn", ",", "'(objectClass=*)'", ",", "$", "attribs", ")", ";", "if", "(", "$", "entries", "===", "false", ")", "{", "return", "$", "group_members", ";", "}", "}", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "entries", "[", "'count'", "]", ";", "$", "i", "++", ")", "{", "$", "entry", "=", "$", "entries", "[", "$", "i", "]", ";", "$", "attrs", "=", "array", "(", ")", ";", "foreach", "(", "(", "array", ")", "$", "entry", "[", "'objectclass'", "]", "as", "$", "objectclass", ")", "{", "if", "(", "(", "$", "member_attr", "=", "$", "this", "->", "get_group_member_attr", "(", "array", "(", "$", "objectclass", ")", ",", "''", ")", ")", "&&", "(", "$", "member_attr", "=", "strtolower", "(", "$", "member_attr", ")", ")", "&&", "!", "in_array", "(", "$", "member_attr", ",", "$", "attrs", ")", ")", "{", "$", "members", "=", "$", "this", "->", "_list_group_members", "(", "$", "dn", ",", "$", "entry", ",", "$", "member_attr", ",", "$", "count", ")", ";", "$", "group_members", "=", "array_merge", "(", "$", "group_members", ",", "$", "members", ")", ";", "$", "attrs", "[", "]", "=", "$", "member_attr", ";", "}", "else", "if", "(", "!", "empty", "(", "$", "entry", "[", "'memberurl'", "]", ")", ")", "{", "$", "members", "=", "$", "this", "->", "_list_group_memberurl", "(", "$", "dn", ",", "$", "entry", ",", "$", "count", ")", ";", "$", "group_members", "=", "array_merge", "(", "$", "group_members", ",", "$", "members", ")", ";", "}", "if", "(", "$", "this", "->", "prop", "[", "'sizelimit'", "]", "&&", "count", "(", "$", "group_members", ")", ">", "$", "this", "->", "prop", "[", "'sizelimit'", "]", ")", "{", "break", "2", ";", "}", "}", "}", "return", "array_filter", "(", "$", "group_members", ")", ";", "}" ]
Get all members of the given group @param string Group DN @param boolean Count only @param array Group entries (if called recursively) @return array Accumulated group members
[ "Get", "all", "members", "of", "the", "given", "group" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_ldap.php#L607-L644
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_ldap.php
rcube_ldap._list_group_members
private function _list_group_members($dn, $entry, $attr, $count) { // Use the member attributes to return an array of member ldap objects // NOTE that the member attribute is supposed to contain a DN $group_members = array(); if (empty($entry[$attr])) { return $group_members; } // read these attributes for all members $attrib = $count ? array('dn','objectClass') : $this->prop['list_attributes']; $attrib = array_merge($attrib, array_values($this->group_types)); $attrib[] = 'memberURL'; $filter = $this->prop['groups']['member_filter'] ?: '(objectclass=*)'; for ($i=0; $i < $entry[$attr]['count']; $i++) { if (empty($entry[$attr][$i])) continue; $members = $this->ldap->read_entries($entry[$attr][$i], $filter, $attrib); if ($members == false) { $members = array(); } // for nested groups, call recursively $nested_group_members = $this->list_group_members($entry[$attr][$i], $count, $members); unset($members['count']); $group_members = array_merge($group_members, array_filter($members), $nested_group_members); } return $group_members; }
php
private function _list_group_members($dn, $entry, $attr, $count) { // Use the member attributes to return an array of member ldap objects // NOTE that the member attribute is supposed to contain a DN $group_members = array(); if (empty($entry[$attr])) { return $group_members; } // read these attributes for all members $attrib = $count ? array('dn','objectClass') : $this->prop['list_attributes']; $attrib = array_merge($attrib, array_values($this->group_types)); $attrib[] = 'memberURL'; $filter = $this->prop['groups']['member_filter'] ?: '(objectclass=*)'; for ($i=0; $i < $entry[$attr]['count']; $i++) { if (empty($entry[$attr][$i])) continue; $members = $this->ldap->read_entries($entry[$attr][$i], $filter, $attrib); if ($members == false) { $members = array(); } // for nested groups, call recursively $nested_group_members = $this->list_group_members($entry[$attr][$i], $count, $members); unset($members['count']); $group_members = array_merge($group_members, array_filter($members), $nested_group_members); } return $group_members; }
[ "private", "function", "_list_group_members", "(", "$", "dn", ",", "$", "entry", ",", "$", "attr", ",", "$", "count", ")", "{", "// Use the member attributes to return an array of member ldap objects", "// NOTE that the member attribute is supposed to contain a DN", "$", "group_members", "=", "array", "(", ")", ";", "if", "(", "empty", "(", "$", "entry", "[", "$", "attr", "]", ")", ")", "{", "return", "$", "group_members", ";", "}", "// read these attributes for all members", "$", "attrib", "=", "$", "count", "?", "array", "(", "'dn'", ",", "'objectClass'", ")", ":", "$", "this", "->", "prop", "[", "'list_attributes'", "]", ";", "$", "attrib", "=", "array_merge", "(", "$", "attrib", ",", "array_values", "(", "$", "this", "->", "group_types", ")", ")", ";", "$", "attrib", "[", "]", "=", "'memberURL'", ";", "$", "filter", "=", "$", "this", "->", "prop", "[", "'groups'", "]", "[", "'member_filter'", "]", "?", ":", "'(objectclass=*)'", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "entry", "[", "$", "attr", "]", "[", "'count'", "]", ";", "$", "i", "++", ")", "{", "if", "(", "empty", "(", "$", "entry", "[", "$", "attr", "]", "[", "$", "i", "]", ")", ")", "continue", ";", "$", "members", "=", "$", "this", "->", "ldap", "->", "read_entries", "(", "$", "entry", "[", "$", "attr", "]", "[", "$", "i", "]", ",", "$", "filter", ",", "$", "attrib", ")", ";", "if", "(", "$", "members", "==", "false", ")", "{", "$", "members", "=", "array", "(", ")", ";", "}", "// for nested groups, call recursively", "$", "nested_group_members", "=", "$", "this", "->", "list_group_members", "(", "$", "entry", "[", "$", "attr", "]", "[", "$", "i", "]", ",", "$", "count", ",", "$", "members", ")", ";", "unset", "(", "$", "members", "[", "'count'", "]", ")", ";", "$", "group_members", "=", "array_merge", "(", "$", "group_members", ",", "array_filter", "(", "$", "members", ")", ",", "$", "nested_group_members", ")", ";", "}", "return", "$", "group_members", ";", "}" ]
Fetch members of the given group entry from server @param string Group DN @param array Group entry @param string Member attribute to use @param boolean Count only @return array Accumulated group members
[ "Fetch", "members", "of", "the", "given", "group", "entry", "from", "server" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_ldap.php#L655-L688
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_ldap.php
rcube_ldap._list_group_memberurl
private function _list_group_memberurl($dn, $entry, $count) { $group_members = array(); for ($i=0; $i < $entry['memberurl']['count']; $i++) { // extract components from url if (!preg_match('!ldap://[^/]*/([^\?]+)\?\?(\w+)\?(.*)$!', $entry['memberurl'][$i], $m)) { continue; } // add search filter if any $filter = $this->filter ? '(&(' . $m[3] . ')(' . $this->filter . '))' : $m[3]; $attrs = $count ? array('dn','objectClass') : $this->prop['list_attributes']; if ($result = $this->ldap->search($m[1], $filter, $m[2], $attrs, $this->group_data)) { $entries = $result->entries(); for ($j = 0; $j < $entries['count']; $j++) { if ($this->is_group_entry($entries[$j]) && ($nested_group_members = $this->list_group_members($entries[$j]['dn'], $count))) $group_members = array_merge($group_members, $nested_group_members); else $group_members[] = $entries[$j]; } } } return $group_members; }
php
private function _list_group_memberurl($dn, $entry, $count) { $group_members = array(); for ($i=0; $i < $entry['memberurl']['count']; $i++) { // extract components from url if (!preg_match('!ldap://[^/]*/([^\?]+)\?\?(\w+)\?(.*)$!', $entry['memberurl'][$i], $m)) { continue; } // add search filter if any $filter = $this->filter ? '(&(' . $m[3] . ')(' . $this->filter . '))' : $m[3]; $attrs = $count ? array('dn','objectClass') : $this->prop['list_attributes']; if ($result = $this->ldap->search($m[1], $filter, $m[2], $attrs, $this->group_data)) { $entries = $result->entries(); for ($j = 0; $j < $entries['count']; $j++) { if ($this->is_group_entry($entries[$j]) && ($nested_group_members = $this->list_group_members($entries[$j]['dn'], $count))) $group_members = array_merge($group_members, $nested_group_members); else $group_members[] = $entries[$j]; } } } return $group_members; }
[ "private", "function", "_list_group_memberurl", "(", "$", "dn", ",", "$", "entry", ",", "$", "count", ")", "{", "$", "group_members", "=", "array", "(", ")", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "entry", "[", "'memberurl'", "]", "[", "'count'", "]", ";", "$", "i", "++", ")", "{", "// extract components from url", "if", "(", "!", "preg_match", "(", "'!ldap://[^/]*/([^\\?]+)\\?\\?(\\w+)\\?(.*)$!'", ",", "$", "entry", "[", "'memberurl'", "]", "[", "$", "i", "]", ",", "$", "m", ")", ")", "{", "continue", ";", "}", "// add search filter if any", "$", "filter", "=", "$", "this", "->", "filter", "?", "'(&('", ".", "$", "m", "[", "3", "]", ".", "')('", ".", "$", "this", "->", "filter", ".", "'))'", ":", "$", "m", "[", "3", "]", ";", "$", "attrs", "=", "$", "count", "?", "array", "(", "'dn'", ",", "'objectClass'", ")", ":", "$", "this", "->", "prop", "[", "'list_attributes'", "]", ";", "if", "(", "$", "result", "=", "$", "this", "->", "ldap", "->", "search", "(", "$", "m", "[", "1", "]", ",", "$", "filter", ",", "$", "m", "[", "2", "]", ",", "$", "attrs", ",", "$", "this", "->", "group_data", ")", ")", "{", "$", "entries", "=", "$", "result", "->", "entries", "(", ")", ";", "for", "(", "$", "j", "=", "0", ";", "$", "j", "<", "$", "entries", "[", "'count'", "]", ";", "$", "j", "++", ")", "{", "if", "(", "$", "this", "->", "is_group_entry", "(", "$", "entries", "[", "$", "j", "]", ")", "&&", "(", "$", "nested_group_members", "=", "$", "this", "->", "list_group_members", "(", "$", "entries", "[", "$", "j", "]", "[", "'dn'", "]", ",", "$", "count", ")", ")", ")", "$", "group_members", "=", "array_merge", "(", "$", "group_members", ",", "$", "nested_group_members", ")", ";", "else", "$", "group_members", "[", "]", "=", "$", "entries", "[", "$", "j", "]", ";", "}", "}", "}", "return", "$", "group_members", ";", "}" ]
List members of group class groupOfUrls @param string Group DN @param array Group entry @param boolean True if only used for counting @return array Accumulated group members
[ "List", "members", "of", "group", "class", "groupOfUrls" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_ldap.php#L698-L723
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_ldap.php
rcube_ldap._entry_sort_cmp
function _entry_sort_cmp($a, $b) { return strcmp($a[$this->sort_col][0], $b[$this->sort_col][0]); }
php
function _entry_sort_cmp($a, $b) { return strcmp($a[$this->sort_col][0], $b[$this->sort_col][0]); }
[ "function", "_entry_sort_cmp", "(", "$", "a", ",", "$", "b", ")", "{", "return", "strcmp", "(", "$", "a", "[", "$", "this", "->", "sort_col", "]", "[", "0", "]", ",", "$", "b", "[", "$", "this", "->", "sort_col", "]", "[", "0", "]", ")", ";", "}" ]
Callback for sorting entries
[ "Callback", "for", "sorting", "entries" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_ldap.php#L728-L731
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_ldap.php
rcube_ldap.delete_all
function delete_all($with_groups = false) { // searching for contact entries $dn_list = $this->ldap->list_entries($this->base_dn, $this->prop['filter'] ?: '(objectclass=*)'); if (!empty($dn_list)) { foreach ($dn_list as $idx => $entry) { $dn_list[$idx] = self::dn_encode($entry['dn']); } $this->delete($dn_list); } if ($with_groups && $this->groups && ($groups = $this->_fetch_groups()) && count($groups)) { foreach ($groups as $group) { $this->ldap->delete_entry($group['dn']); } if ($this->cache) { $this->cache->remove('groups'); } } }
php
function delete_all($with_groups = false) { // searching for contact entries $dn_list = $this->ldap->list_entries($this->base_dn, $this->prop['filter'] ?: '(objectclass=*)'); if (!empty($dn_list)) { foreach ($dn_list as $idx => $entry) { $dn_list[$idx] = self::dn_encode($entry['dn']); } $this->delete($dn_list); } if ($with_groups && $this->groups && ($groups = $this->_fetch_groups()) && count($groups)) { foreach ($groups as $group) { $this->ldap->delete_entry($group['dn']); } if ($this->cache) { $this->cache->remove('groups'); } } }
[ "function", "delete_all", "(", "$", "with_groups", "=", "false", ")", "{", "// searching for contact entries", "$", "dn_list", "=", "$", "this", "->", "ldap", "->", "list_entries", "(", "$", "this", "->", "base_dn", ",", "$", "this", "->", "prop", "[", "'filter'", "]", "?", ":", "'(objectclass=*)'", ")", ";", "if", "(", "!", "empty", "(", "$", "dn_list", ")", ")", "{", "foreach", "(", "$", "dn_list", "as", "$", "idx", "=>", "$", "entry", ")", "{", "$", "dn_list", "[", "$", "idx", "]", "=", "self", "::", "dn_encode", "(", "$", "entry", "[", "'dn'", "]", ")", ";", "}", "$", "this", "->", "delete", "(", "$", "dn_list", ")", ";", "}", "if", "(", "$", "with_groups", "&&", "$", "this", "->", "groups", "&&", "(", "$", "groups", "=", "$", "this", "->", "_fetch_groups", "(", ")", ")", "&&", "count", "(", "$", "groups", ")", ")", "{", "foreach", "(", "$", "groups", "as", "$", "group", ")", "{", "$", "this", "->", "ldap", "->", "delete_entry", "(", "$", "group", "[", "'dn'", "]", ")", ";", "}", "if", "(", "$", "this", "->", "cache", ")", "{", "$", "this", "->", "cache", "->", "remove", "(", "'groups'", ")", ";", "}", "}", "}" ]
Remove all contact records @param bool $with_groups Delete also groups if enabled
[ "Remove", "all", "contact", "records" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_ldap.php#L1433-L1454
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_ldap.php
rcube_ldap.add_autovalues
protected function add_autovalues(&$attrs) { if (empty($this->prop['autovalues'])) { return; } $attrvals = array(); foreach ($attrs as $k => $v) { $attrvals['{'.$k.'}'] = is_array($v) ? $v[0] : $v; } foreach ((array)$this->prop['autovalues'] as $lf => $templ) { if (empty($attrs[$lf])) { if (strpos($templ, '(') !== false) { // replace {attr} placeholders with (escaped!) attribute values to be safely eval'd $code = preg_replace('/\{\w+\}/', '', strtr($templ, array_map('addslashes', $attrvals))); $res = false; try { $res = eval("return ($code);"); } catch (ParseError $e) { // ignore } if ($res === false) { rcube::raise_error(array( 'code' => 505, 'file' => __FILE__, 'line' => __LINE__, 'message' => "Expression parse error on: ($code)"), true, false); continue; } $attrs[$lf] = $res; } else { // replace {attr} placeholders with concrete attribute values $attrs[$lf] = preg_replace('/\{\w+\}/', '', strtr($templ, $attrvals)); } } } }
php
protected function add_autovalues(&$attrs) { if (empty($this->prop['autovalues'])) { return; } $attrvals = array(); foreach ($attrs as $k => $v) { $attrvals['{'.$k.'}'] = is_array($v) ? $v[0] : $v; } foreach ((array)$this->prop['autovalues'] as $lf => $templ) { if (empty($attrs[$lf])) { if (strpos($templ, '(') !== false) { // replace {attr} placeholders with (escaped!) attribute values to be safely eval'd $code = preg_replace('/\{\w+\}/', '', strtr($templ, array_map('addslashes', $attrvals))); $res = false; try { $res = eval("return ($code);"); } catch (ParseError $e) { // ignore } if ($res === false) { rcube::raise_error(array( 'code' => 505, 'file' => __FILE__, 'line' => __LINE__, 'message' => "Expression parse error on: ($code)"), true, false); continue; } $attrs[$lf] = $res; } else { // replace {attr} placeholders with concrete attribute values $attrs[$lf] = preg_replace('/\{\w+\}/', '', strtr($templ, $attrvals)); } } } }
[ "protected", "function", "add_autovalues", "(", "&", "$", "attrs", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "prop", "[", "'autovalues'", "]", ")", ")", "{", "return", ";", "}", "$", "attrvals", "=", "array", "(", ")", ";", "foreach", "(", "$", "attrs", "as", "$", "k", "=>", "$", "v", ")", "{", "$", "attrvals", "[", "'{'", ".", "$", "k", ".", "'}'", "]", "=", "is_array", "(", "$", "v", ")", "?", "$", "v", "[", "0", "]", ":", "$", "v", ";", "}", "foreach", "(", "(", "array", ")", "$", "this", "->", "prop", "[", "'autovalues'", "]", "as", "$", "lf", "=>", "$", "templ", ")", "{", "if", "(", "empty", "(", "$", "attrs", "[", "$", "lf", "]", ")", ")", "{", "if", "(", "strpos", "(", "$", "templ", ",", "'('", ")", "!==", "false", ")", "{", "// replace {attr} placeholders with (escaped!) attribute values to be safely eval'd", "$", "code", "=", "preg_replace", "(", "'/\\{\\w+\\}/'", ",", "''", ",", "strtr", "(", "$", "templ", ",", "array_map", "(", "'addslashes'", ",", "$", "attrvals", ")", ")", ")", ";", "$", "res", "=", "false", ";", "try", "{", "$", "res", "=", "eval", "(", "\"return ($code);\"", ")", ";", "}", "catch", "(", "ParseError", "$", "e", ")", "{", "// ignore", "}", "if", "(", "$", "res", "===", "false", ")", "{", "rcube", "::", "raise_error", "(", "array", "(", "'code'", "=>", "505", ",", "'file'", "=>", "__FILE__", ",", "'line'", "=>", "__LINE__", ",", "'message'", "=>", "\"Expression parse error on: ($code)\"", ")", ",", "true", ",", "false", ")", ";", "continue", ";", "}", "$", "attrs", "[", "$", "lf", "]", "=", "$", "res", ";", "}", "else", "{", "// replace {attr} placeholders with concrete attribute values", "$", "attrs", "[", "$", "lf", "]", "=", "preg_replace", "(", "'/\\{\\w+\\}/'", ",", "''", ",", "strtr", "(", "$", "templ", ",", "$", "attrvals", ")", ")", ";", "}", "}", "}", "}" ]
Generate missing attributes as configured @param array LDAP record attributes
[ "Generate", "missing", "attributes", "as", "configured" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_ldap.php#L1461-L1501
train