1 package FS::acct_snarf;
2 use base qw(FS::Record);
6 use FS::Record qw( qsearchs );
11 FS::acct_snarf - Object methods for acct_snarf records
17 $record = new FS::acct_snarf \%hash;
18 $record = new FS::acct_snarf { 'column' => 'value' };
20 $error = $record->insert;
22 $error = $new_record->replace($old_record);
24 $error = $record->delete;
26 $error = $record->check;
30 An FS::svc_acct object represents an external mail account, typically for
31 download of mail. FS::acct_snarf inherits from FS::Record. The following
32 fields are currently supported:
36 =item snarfnum - primary key
38 =item snarfname - Label
40 =item svcnum - Account (see L<FS::svc_acct>)
42 =item machine - external machine to download mail from
44 =item protocol - protocol (pop3, imap, etc.)
46 =item username - external login username
48 =item _password - external login password
58 Creates a new record. To add the record to the database, see L<"insert">.
60 Note that this stores the hash reference, not a distinct copy of the hash it
61 points to. You can ask the object for a copy with the I<hash> method.
65 sub table { 'acct_snarf'; }
69 Adds this record to the database. If there is an error, returns the error,
70 otherwise returns false.
74 # the insert method can be inherited from FS::Record
78 Delete this record from the database.
82 # the delete method can be inherited from FS::Record
84 =item replace OLD_RECORD
86 Replaces the OLD_RECORD with this one in the database. If there is an error,
87 returns the error, otherwise returns false.
91 # the replace method can be inherited from FS::Record
99 qsearchs('cust_svc', { 'svcnum' => $self->svcnum } );
105 Calls the replace export for any communigate exports attached to this rule's
113 my $cust_svc = $self->cust_svc;
114 my $svc_x = $cust_svc->svc_x;
117 my @exports = $cust_svc->part_svc->part_export('communigate_pro');
118 my @errors = map $_->export_replace($svc_x, $svc_x), @exports;
120 @errors ? join(' / ', @errors) : '';
126 Checks all fields to make sure this is a valid external mail account. If
127 there is an error, returns the error, otherwise returns false. Called by the
128 insert and replace methods.
135 $self->ut_numbern('snarfnum')
136 || $self->ut_textn('snarfname') #alphasn?
137 || $self->ut_number('svcnum')
138 || $self->ut_foreign_key('svcnum', 'svc_acct', 'svcnum')
139 || $self->ut_domain('machine')
140 || $self->ut_alphan('protocol')
141 || $self->ut_textn('username')
142 || $self->ut_numbern('check_freq')
143 || $self->ut_enum('leavemail', [ '', 'Y' ])
144 || $self->ut_enum('apop', [ '', 'Y' ])
145 || $self->ut_enum('tls', [ '', 'Y' ])
146 || $self->ut_alphan('mailbox')
148 return $error if $error;
150 $self->_password =~ /^[^\t\n]*$/ or return "illegal password";
151 $self->_password($1);
156 sub check_freq_labels {
158 tie my %hash, 'Tie::IxHash',
166 1800 => '30 minutes',
176 1000000000 => 'Disabled',
184 Returns a hashref representing this external mail account, suitable for
185 Communigate Pro API commands:
192 'authName' => $self->username,
193 'domain' => $self->machine,
194 'password' => $self->_password,
195 'period' => $self->check_freq.'s',
196 'APOP' => ( $self->apop eq 'Y' ? 'YES' : 'NO' ),
197 'TLS' => ( $self->tls eq 'Y' ? 'YES' : 'NO' ),
198 'Leave' => ( $self->leavemail eq 'Y' ? 'YES' : 'NO' ), #XXX leave??
208 L<FS::Record>, schema.html from the base documentation.