function mailhandler_node_process_message_commands in Mailhandler 6
Same name and namespace in other branches
- 7 mailhandler.module \mailhandler_node_process_message_commands()
2 calls to mailhandler_node_process_message_commands()
- MailhandlerProcessingTestCase::testMailhandlerCommandsParse in ./mailhandler.test
- Verify the commands parsing functionality.
- mailhandler_node_prepare_message in ./mailhandler.module
- Append default commands. Separate commands from body. Strip signature.
Return a node object.
File
- ./mailhandler.module, line 1034
- Mailhandler module code.
Code
function mailhandler_node_process_message_commands(&$node, $commands) {
foreach ($commands as $data) {
if (substr($data[1], 0, 1) == '[' && substr($data[1], -1, 1) == ']') {
$data[1] = rtrim(ltrim($data[1], '['), ']');
$data[1] = explode(",", $data[1]);
foreach ($data[1] as $key => $value) {
$data_tmp = explode(":", $value, 2);
if (isset($data_tmp[1])) {
unset($data[1][$key]);
$data_tmp[0] = trim($data_tmp[0]);
$data[1][$data_tmp[0]] = $data_tmp[1];
}
}
}
$data[0] = strtolower(str_replace(' ', '_', $data[0]));
if (($data[0] == 'taxonomy' || $data[0] == 'taxonomy') && module_exists('taxonomy')) {
$vocabs = taxonomy_get_vocabularies($node->type);
$node->taxonomy = array();
if ($data[0] == 'taxonomy' && !is_numeric($data[1][0])) {
array_walk($data[1], 'mailhandler_term_map');
$term = taxonomy_get_term($data[1][0]);
if (array_key_exists($term->vid, $vocabs)) {
$node->taxonomy = array_merge($node->taxonomy, $data[1]);
}
unset($data[0]);
}
else {
if (substr($data[0], 0, 9) == 'taxonomy[' && substr($data[0], -1, 1) == ']') {
$vid = substr($data[0], 9, -1);
$vocabulary = taxonomy_vocabulary_load($vid);
if (!in_array($node->type, $vocabulary->nodes)) {
unset($data[0]);
}
else {
if (!$vocabulary->tags) {
array_walk($data[1], 'mailhandler_term_map', $vid);
$node->taxonomy = array_merge($node->taxonomy, $data[1]);
unset($data[0]);
}
else {
if ($vocabulary->tags) {
$node->taxonomy['tags'][$vid] = implode(',', $data[1]);
unset($data[0]);
}
}
}
}
}
}
if (!empty($data[0])) {
$node->{$data}[0] = $data[1];
}
}
}