You are here

function mailhandler_commands_parse in Mailhandler 6

Same name and namespace in other branches
  1. 7 mailhandler.retrieve.inc \mailhandler_commands_parse()
1 call to mailhandler_commands_parse()
mailhandler_node_prepare_message in ./mailhandler.module
Append default commands. Separate commands from body. Strip signature. Return a node object.

File

./mailhandler.retrieve.inc, line 183
Mailbox connection code.

Code

function mailhandler_commands_parse($body, $sep) {
  $commands = array();

  // Collect the commands and locate signature
  $lines = explode("\n", $body);
  for ($i = 0; $i < count($lines); $i++) {
    $line = trim($lines[$i]);
    $words = explode(' ', $line);

    // Look for a command line. if not present, note which line number is the boundary
    if (substr($words[0], -1) == ':' && !isset($endcommands)) {

      // Looks like a name: value pair
      $commands[$i] = explode(': ', $line, 2);
    }
    else {
      if (!isset($endcommands)) {
        $endcommands = $i;
      }
    }

    // Stop when we encounter the sig. we'll discard all remaining text.
    $start = substr($lines[$i], 0, strlen($sep) + 3);
    if ($sep && strstr($start, $sep)) {

      // mail clients sometimes prefix replies with ' >'
      break;
    }
  }
  return array(
    'commands' => $commands,
    'lines' => $lines,
    'i' => $i,
    'endcommands' => $endcommands,
  );
}