diff --git a/includes/simplenews.source.inc b/includes/simplenews.source.inc index ab4897b..1440a47 100644 --- a/includes/simplenews.source.inc +++ b/includes/simplenews.source.inc @@ -298,6 +298,16 @@ class SimplenewsSpool implements SimplenewsSpoolInterface { $subscriber = simplenews_subscriber_load_by_mail($spool_data->mail); } + if (!$subscriber) { + // If loading the subscriber failed, set the processed status done and + // proceed with the next mail. + $this->processed[$spool_data->msid]->result = array( + 'status' => SIMPLENEWS_SPOOL_DONE, + 'error' => TRUE + ); + return $this->nextSource(); + } + $source_class = $this->getSourceImplementation($spool_data); $source = new $source_class($node, $subscriber); diff --git a/tests/simplenews.test b/tests/simplenews.test index c5bd3ce..c0eb6a6 100644 --- a/tests/simplenews.test +++ b/tests/simplenews.test @@ -2892,6 +2892,36 @@ class SimplenewsSourceTestCase extends SimplenewsTestCase { $spool_row = db_query('SELECT * FROM {simplenews_mail_spool}')->fetchObject(); $this->assertEqual(SIMPLENEWS_SPOOL_DONE, $spool_row->status); } + + /** + * Test with disabled caching. + */ + function testSendMissingSubscriber() { + $this->setUpSubscribers(1); + + $edit = array( + 'title' => $this->randomName(), + 'body[und][0][value]' => "Mail token: [simplenews-subscriber:mail]", + ); + $this->drupalPost('node/add/simplenews', $edit, ('Save')); + $this->assertTrue(preg_match('|node/(\d+)$|', $this->getUrl(), $matches), 'Node created'); + $node = node_load($matches[1]); + + // Add node to spool. + simplenews_add_node_to_spool($node); + + // Delete the subscriber. + $subscriber = simplenews_subscriber_load_by_mail(reset($this->subscribers)); + simplenews_subscriber_delete($subscriber); + + simplenews_mail_spool(); + + // Make sure that no mails have been sent. + $this->assertEqual(0, count($this->drupalGetMails())); + + $spool_row = db_query('SELECT * FROM {simplenews_mail_spool}')->fetchObject(); + $this->assertEqual(SIMPLENEWS_SPOOL_DONE, $spool_row->status); + } } /**