1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196
|
<?php
# $Id$
/**
* Handler for fetchmail jobs
*/
class FetchmailHandler extends PFAHandler
{
protected $db_table = 'fetchmail';
protected $id_field = 'id';
protected $domain_field = 'domain';
protected $order_by = 'domain, mailbox';
protected function initStruct()
{
$src_auth_options = array('password','kerberos_v5','kerberos','kerberos_v4','gssapi','cram-md5','otp','ntlm','msn','ssh','any');
$src_protocol_options = array('POP3','IMAP','POP2','ETRN','AUTO');
$extra = Config::intbool('fetchmail_extra_options');
$this->struct = array(
# field name allow display in... type $PALANG label $PALANG description default / options / ...
# editing? form list
'id' => self::pacol(0, 0, 1, 'num' , '' , '' , '', array(),
array('dont_write_to_db' => 1)),
'domain' => self::pacol(0, 0, 1, 'text', '' , ''),
'mailbox' => self::pacol(1, 1, 1, 'enum', 'pFetchmail_field_mailbox' , 'pFetchmail_desc_mailbox'), # mailbox list
'src_server' => self::pacol(1, 1, 1, 'text', 'pFetchmail_field_src_server' , 'pFetchmail_desc_src_server'),
'src_port' => self::pacol(1, 1, 1, 'num', 'pFetchmail_field_src_port' , 'pFetchmail_desc_src_port' , 0),
'src_auth' => self::pacol(1, 1, 1, 'enum', 'pFetchmail_field_src_auth' , 'pFetchmail_desc_src_auth' , '', $src_auth_options),
'src_user' => self::pacol(1, 1, 1, 'text', 'pFetchmail_field_src_user' , 'pFetchmail_desc_src_user'),
'src_password' => self::pacol(1, 1, 0, 'b64p', 'pFetchmail_field_src_password' , 'pFetchmail_desc_src_password'),
'src_folder' => self::pacol(1, 1, 1, 'text', 'pFetchmail_field_src_folder' , 'pFetchmail_desc_src_folder'),
'poll_time' => self::pacol(1, 1, 1, 'num' , 'pFetchmail_field_poll_time' , 'pFetchmail_desc_poll_time' , 10),
'fetchall' => self::pacol(1, 1, 1, 'bool', 'pFetchmail_field_fetchall' , 'pFetchmail_desc_fetchall'),
'keep' => self::pacol(1, 1, 1, 'bool', 'pFetchmail_field_keep' , 'pFetchmail_desc_keep'),
'protocol' => self::pacol(1, 1, 1, 'enum', 'pFetchmail_field_protocol' , 'pFetchmail_desc_protocol' , '', $src_protocol_options),
'usessl' => self::pacol(1, 1, 1, 'bool', 'pFetchmail_field_usessl' , 'pFetchmail_desc_usessl'),
'sslcertck' => self::pacol(1, 1, 1, 'bool', 'pFetchmail_field_sslcertck' , ''),
'sslcertpath' => self::pacol($extra, $extra, $extra, 'text', 'pFetchmail_field_sslcertpath' , ''),
'sslfingerprint' => self::pacol($extra, $extra, $extra, 'text', 'pFetchmail_field_sslfingerprint',''),
'extra_options' => self::pacol($extra, $extra, $extra, 'text', 'pFetchmail_field_extra_options', 'pFetchmail_desc_extra_options'),
'mda' => self::pacol($extra, $extra, $extra, 'text', 'pFetchmail_field_mda' , 'pFetchmail_desc_mda'),
'date' => self::pacol(0, 0, 1, 'text', 'pFetchmail_field_date' , 'pFetchmail_desc_date' , '2000-01-01'),
'returned_text' => self::pacol(0, 0, 1, 'text', 'pFetchmail_field_returned_text', 'pFetchmail_desc_returned_text'),
'active' => self::pacol(1, 1, 1, 'bool', 'active' , '' , 1),
'created' => self::pacol(0, 0, 0, 'ts', 'created' , ''),
'modified' => self::pacol(0, 0, 1, 'ts', 'last_modified' , ''),
);
# get list of mailboxes (for currently logged in user)
$handler = new MailboxHandler(0, $this->admin_username);
$handler->getList('1=1');
$this->struct['mailbox']['options'] = array_keys($handler->result);
}
protected function initMsg()
{
$this->msg['error_already_exists'] = 'fetchmail_already_exists';
$this->msg['error_does_not_exist'] = 'fetchmail_does_not_exist';
$this->msg['confirm_delete'] = 'confirm_delete_fetchmail';
if ($this->new) {
$this->msg['logname'] = 'create_fetchmail';
$this->msg['store_error'] = 'pFetchmail_database_save_error';
$this->msg['successmessage'] = 'pFetchmail_database_save_success';
} else {
$this->msg['logname'] = 'edit_fetchmail';
$this->msg['store_error'] = 'pFetchmail_database_save_error';
$this->msg['successmessage'] = 'pFetchmail_database_save_success';
}
}
public function webformConfig()
{
return array(
# $PALANG labels
'formtitle_create' => 'pMenu_fetchmail',
'formtitle_edit' => 'pMenu_fetchmail',
'create_button' => 'pFetchmail_new_entry',
# various settings
'required_role' => 'admin',
'listview' => 'list.php?table=fetchmail',
'early_init' => 0,
'prefill' => array('mailbox'),
);
}
protected function setmore(array $values)
{
# set domain based on the target mailbox
if ($this->new || isset($values['mailbox'])) {
list(/*NULL*/, $domain) = explode('@', $values['mailbox']);
$this->values['domain'] = $domain;
$this->domain = $domain;
}
}
protected function validate_new_id()
{
# auto_increment - any non-empty ID is an error
if ($this->id != '') {
$this->errormsg[$this->id_field] = 'auto_increment value, you must pass an empty string!';
return false;
}
return true;
}
/**
* @return boolean
*/
public function delete()
{
if (! $this->view()) {
$this->errormsg[] = Config::lang($this->msg['error_does_not_exist']);
return false;
}
db_delete($this->db_table, $this->id_field, $this->id);
db_log($this->id, 'delete_fetchmail', $this->result['id']);
$this->infomsg[] = Config::Lang_f('pDelete_delete_success', $this->result['src_user'] . ' -> ' . $this->result['mailbox']);
return true;
}
/**
* validate src_server - must be non-empty and survive check_domain()
*/
protected function _validate_src_server($field, $val)
{
if ($val == '') {
$msg = Config::Lang('pFetchmail_server_missing');
} else {
$msg = check_domain($val);
}
if ($msg == '') {
return true;
} else {
$this->errormsg[$field] = $msg;
return false;
}
}
/**
* validate src_user and src_password - must be non-empty
* (we can't assume anything about valid usernames and passwords on remote
* servers, so the validation can't be more strict)
*/
protected function _validate_src_user($field, $val)
{
if ($val == '') {
$this->errormsg[$field] = Config::lang('pFetchmail_user_missing');
return false;
}
return true;
}
protected function _validate_src_password($field, $val)
{
if ($val == '') {
$this->errormsg[$field] = Config::lang('pFetchmail_password_missing');
return false;
}
return true;
}
/**
* validate poll interval - must be numeri and > 0
*/
protected function _validate_poll_time($field, $val)
{
# must be > 0
if ($val < 1) {
$this->errormsg[$field] = Config::Lang_f('must_be_numeric_bigger_than_null', $field);
return false;
}
return true;
}
public function domain_from_id()
{
return '';
}
}
/* vim: set expandtab softtabstop=4 tabstop=4 shiftwidth=4: */
|