/**
  * Find mailbox by from_email field
  *
  * @param string $email
  * @return IncomingMailbox
  */
 function findByFromEmail($email)
 {
     return IncomingMailboxes::find(array('conditions' => array('from_email = ?', $email), 'limit' => 1, 'one' => true));
 }
 /**
  * Main page in administration for Incoming Mail
  *
  */
 function index()
 {
     $config_admin_email = ConfigOptions::getValue('notifications_from_email');
     $notifications_email = $config_admin_email ? $config_admin_email : ADMIN_EMAIL;
     $default_mailbox = IncomingMailboxes::findByFromEmail($notifications_email);
     $add_default_mailbox_url = assemble_url('incoming_mail_admin_add_mailbox', array('default_email_address' => $notifications_email));
     if (!instance_of($default_mailbox, 'IncomingMailbox')) {
         $this->wireframe->addPageMessage(lang('System is not able to receive email messages sent as replies to notifications. If you would like your users to be able to reply to notifications and have their messages automatically submitted as comments please <a href=":add_default_mailbox_url">define an incoming mailbox</a> for <strong>:address</strong>.', array('address' => $notifications_email, 'add_default_mailbox_url' => $add_default_mailbox_url)), PAGE_MESSAGE_WARNING);
     } elseif (!$default_mailbox->getEnabled()) {
         $this->wireframe->addPageMessage(lang('System is not able to receive email messages sent as replies to notifications. If you would like your users to be able to reply to notifications and have their messages automatically submitted as comments please <a href=":edit_default_mailbox_url">enable default incoming mailbox</a>.', array('edit_default_mailbox_url' => $default_mailbox->getEditUrl())), PAGE_MESSAGE_WARNING);
     }
     // if
     if (!MM_CAN_DOWNLOAD_LARGE_ATTACHMENTS) {
         $limited_filesize = format_file_size(FAIL_SAFE_IMAP_ATTACHMENT_SIZE_MAX);
         if (!function_exists('imap_savebody')) {
             $this->wireframe->addPageMessage(lang("<b>Your PHP version is obsolete</b> - You won't be able to download attachments larger than <b>:file_size</b>. Please upgrade to latest stable version of PHP to solve this issue.", array('file_size' => $limited_filesize)), PAGE_MESSAGE_WARNING);
         } else {
             $this->wireframe->addPageMessage(lang("Importing attachments larger than <b>:file_size</b> is disabled. Module uses failsafe IMAP functions due to platform restrictions.", array('file_size' => $limited_filesize)), PAGE_MESSAGE_WARNING);
         }
         // if
     }
     // if
     use_model('incoming_mail_activity_logs', INCOMING_MAIL_MODULE);
     $per_page = 50;
     // mailbox activity per page
     $page = (int) $this->request->get('page');
     if ($page < 1) {
         $page = 1;
     }
     // if
     $only_problematic = (bool) array_var($_GET, 'only_problematic', false);
     if ($only_problematic) {
         list($activity_history, $pagination) = IncomingMailActivityLogs::paginateConflicts($page, $per_page);
     } else {
         list($activity_history, $pagination) = IncomingMailActivityLogs::paginate(array('order' => 'created_on DESC'), $page, $per_page);
     }
     // if
     $activity_history = group_by_date($activity_history);
     $this->smarty->assign(array('mailboxes' => IncomingMailboxes::find(), 'activity_history' => $activity_history, 'pagination' => $pagination, 'only_problematic' => $only_problematic));
 }