/**
  * Get all the fetchmail account configured (can specify a user id to retrieve only account for a single user)
  * @param MDB2 $dbm database connection
  * @param int $user_id
  */
 public function __construct($dbm, $user_id = -1)
 {
     $this->dbm = $dbm;
     $this->position = 0;
     // Retrieve the accounts list
     if ($user_id != -1) {
         $sql_result = $this->dbm->query("SELECT * FROM " . get_table_name('fetchmail_rc') . " WHERE fk_user=?", $user_id);
     } else {
         $sql_result = $this->dbm->query("SELECT * FROM " . get_table_name('fetchmail_rc'));
     }
     while ($account = $this->dbm->fetch_assoc($sql_result)) {
         $fetchmailRc = new fetchMailRc();
         $fetchmailRc->from_array($account);
         $this->datas[] = $fetchmailRc;
     }
 }
 private function start_account_reception($test_mode = true)
 {
     require_once dirname(__FILE__) . '/includes/fetchMailRc.php';
     $this->rcmail->output->add_label('fetchmail_rc.error_during_process');
     $id = get_input_value('_fetchmail_rc_id', RCUBE_INPUT_POST);
     try {
         $fetchmailRc = new fetchMailRc($id);
         $fetchmailRc->set_fk_user($this->rcmail->user->data['user_id'])->set_mail_host(get_input_value('_mail_host', RCUBE_INPUT_POST))->set_mail_username(get_input_value('_mail_username', RCUBE_INPUT_POST))->set_mail_password(get_input_value('_mail_password', RCUBE_INPUT_POST))->set_mail_arguments(get_input_value('_mail_arguments', RCUBE_INPUT_POST))->set_mail_protocol(get_input_value('_mail_protocol', RCUBE_INPUT_POST))->set_mail_ssl(get_input_value('_mail_ssl', RCUBE_INPUT_POST));
         if ($test_mode == true) {
             $retrieved = $fetchmailRc->test_account();
         } else {
             $retrieved = $fetchmailRc->retrieve_mails();
         }
     } catch (Exception $e) {
         $this->rcmail->output->command('plugin.retrieve_account_finished', array("error" => $e->getMessage()));
         $this->rcmail->output->send('plugin');
     }
     $vars = array();
     if (!$retrieved) {
         $vars['error'] = $this->gettext("unknown_error_during_retrieve");
     }
     $vars['type'] = $test_mode ? "test" : "retrieve";
     if ($retrieved) {
         $vars['success_message'] = $test_mode ? $this->gettext("test_account_success") : $this->gettext("retrieve_account_success");
     }
     $this->rcmail->output->command('plugin.retrieve_account_finished', $vars);
     $this->rcmail->output->send('plugin');
 }