You are here

function mail_safety_load in Mail Safety 7

Get mail catched by the mail safety module.

If the mail id parameter is omitted it will return all mail.

Parameters

int $mail_id: The mail id as it is saved in the mail safety table.

4 calls to mail_safety_load()
hook_mail_safety_delete_mail in ./mail_safety.api.php
Respond to a mail being deleted.
hook_mail_safety_table_structure_alter in ./mail_safety.api.php
Alter the table structure of the mail safety dashboard.
mail_safety_admin_send_default_form_submit in ./mail_safety.admin.inc
Form submission handler for mail_safety_admin_send_default_form_submit.
mail_safety_admin_send_original_form_submit in ./mail_safety.admin.inc
Form submission handler for mail_safety_admin_send_original_form.

File

./mail_safety.module, line 157
The core Mail Safety module file

Code

function mail_safety_load($mail_id = NULL) {
  $mails = array();
  $query = db_select('mail_safety_dashboard', 'msd');
  $query
    ->fields('msd', array(
    'mail_id',
    'sent',
    'mail',
  ));

  // Add a condition for the mail id is given.
  if (!empty($mail_id) && is_numeric($mail_id)) {
    $query
      ->condition('mail_id', $mail_id);
  }
  $query
    ->orderBy('sent', 'DESC');
  $result = $query
    ->execute();
  while ($row = $result
    ->fetchAssoc()) {
    $mails[$row['mail_id']] = array(
      'mail' => unserialize($row['mail']),
      'sent' => $row['sent'],
      'mail_id' => $row['mail_id'],
    );
  }

  // Let other modules respond before a mail is loaded.
  // E.g. attachments that were saved with the mail.
  $modules = module_implements('mail_safety_load');
  foreach ($mails as $key => $mail) {
    foreach ($modules as $module) {
      $mail['mail'] = module_invoke($module, 'mail_safety_load', $mail['mail']);
    }
    $mails[$key] = $mail;
  }
  if (!is_null($mail_id) && !empty($mails[$mail_id])) {
    return $mails[$mail_id];
  }
  elseif (!empty($mails)) {
    return $mails;
  }
  return FALSE;
}