Index: mailhandler.test
===================================================================
diff -u -r1.1.2.2 mailhandler.test
--- mailhandler.test	26 Jan 2011 11:55:13 -0000	1.1.2.2
+++ mailhandler.test	26 Jan 2011 12:08:15 -0000
@@ -274,6 +274,92 @@
     $this->assertfieldByName('mailhandler_default_encoding', $settings['mailhandler_default_encoding']);
   }
 
+  /*
+   * Verify basic operations, reading a mailbox with three mails where only one
+   * of them is authorized.
+   *
+   * @todo: probably more 'default' cases can be set here, but commands testing
+   * must have its own test function.
+   */
+  function testReadLocalMailbox() {
+
+    // Create a local mailbox, make sure this works on windows.
+    $mailbox = $this->drupalCreateMailbox( array(
+      'folder' => str_replace( '/', DIRECTORY_SEPARATOR , getcwd() . '/'. $this->tempdir . '/simpletest.mbox'),
+    ));
+
+    // Create a dummy account with permissions to create posts using email.
+    $account = $this->drupalCreateUser( array(
+      'create story content',
+    ));
+
+    // Write dummy mailbox content to verify the submission and authentication.
+    // A (default) page content.
+    $mbox  = "From MAILER-DAEMON Sun Oct 24 12:53:43 2010\n";
+    $mbox .= "From: " . $account->name. " <" . $account->mail . ">\n";
+    $mbox .= "To: mailbox <" . $mailbox['mail'] . ">\n";
+    $mbox .= "Subject: Sample message 1\n";
+    $mbox .= "\n";
+    $mbox .= "This is the body of sample message 1.\n";
+    $mbox .= "\n";
+    $mbox .= "\n";
+    // A (non-permissioned) story content.
+    $mbox .= "From MAILER-DAEMON Sun Oct 24 12:53:42 2010\n";
+    $mbox .= "From: " . $account->name. " <" . $account->mail . ">\n";
+    $mbox .= "To: mailbox <" . $mailbox['mail'] . ">\n";
+    $mbox .= "Subject: Sample message 2\n";
+    $mbox .= "\n";
+    $mbox .= "type: page\n";
+    $mbox .= "This is the body of sample message 2.\n";
+    $mbox .= "\n";
+    $mbox .= "\n";
+    // An 'anonymous'randomguy' email, trying to (default) create a page.
+    $mbox .= "From MAILER-DAEMON Sun Oct 24 12:53:41 2010\n";
+    $mbox .= "From: Random user <randomguy@simpletest.domain.tld>\n";
+    $mbox .= "To: mailbox <" . $mailbox['mail'] . ">\n";
+    $mbox .= "Subject: Sample message 3\n";
+    $mbox .= "\n";
+    $mbox .= "This is the body of sample message 3.\n";
+    $mbox .= "\n";
+    $mbox .= "\n";
+
+    // Save this mailbox for testing.
+    file_put_contents($mailbox['folder'], $mbox);
+
+    // Create and login as administrator user.
+    $administrator = $this->drupalCreateUser( array(
+      'administer mailhandler', 'access site reports', 'administer site configuration',
+    ));
+    $this->drupalLogin($administrator);
+
+    // right now, retrieve using UI is broken, use cron so testbot loves the
+    // testcase.
+    $this->drupalGet('admin/reports/status/run-cron');
+
+    // Verify that valid email is converted into content with right attributes.
+    // @additional node verifications can go here.
+    $node = node_load(array('title' => 'Sample message 1'));
+    $this->assertEqual($account->uid, $node->uid, t('Node authorship verified.'));
+
+    // Verify the node content.
+    $this->drupalGet('node/' . $node->nid);
+    $this->assertText('This is the body of sample message 1.');
+
+    // There is one accepted and two rejected entries. Rejected entries get an
+    // email back. Lets see if that happend.
+    $mails = $this->drupalGetMails(array('id' => 'mailhandler_mailhandler_error_node'));
+    $this->assertEqual(count($mails), 2, t('Number of mails sent matches.'));
+
+    $this->assertTrue(
+      strstr(t('The e-mail address !mail may not create page items.', array('!mail' => $account->mail)),
+      $mails[0]['params']['error_text'])
+    );
+    $this->assertTrue(
+      strstr(t('The e-mail address notrandom@simpeltest.domain.tld may not create story items.'),
+      $mails[1]['params']['error_text']
+    ));
+  }
+
   /**
    * Helper functions.
    */

