communigate phase 3: RPOP/acct_snarf, RT#7515
[freeside.git] / FS / FS / acct_snarf.pm
1 package FS::acct_snarf;
2
3 use strict;
4 use vars qw( @ISA );
5 use Tie::IxHash;
6 use FS::Record;
7
8 @ISA = qw( FS::Record );
9
10 =head1 NAME
11
12 FS::acct_snarf - Object methods for acct_snarf records
13
14 =head1 SYNOPSIS
15
16   use FS::acct_snarf;
17
18   $record = new FS::acct_snarf \%hash;
19   $record = new FS::acct_snarf { 'column' => 'value' };
20
21   $error = $record->insert;
22
23   $error = $new_record->replace($old_record);
24
25   $error = $record->delete;
26
27   $error = $record->check;
28
29 =head1 DESCRIPTION
30
31 An FS::svc_acct object represents an external mail account, typically for
32 download of mail.  FS::acct_snarf inherits from FS::Record.  The following
33 fields are currently supported:
34
35 =over 4
36
37 =item snarfnum - primary key
38
39 =item snarfname - Label
40
41 =item svcnum - Account (see L<FS::svc_acct>)
42
43 =item machine - external machine to download mail from
44
45 =item protocol - protocol (pop3, imap, etc.)
46
47 =item username - external login username
48
49 =item _password - external login password
50
51 =back
52
53 =head1 METHODS
54
55 =over 4
56
57 =item new HASHREF
58
59 Creates a new record.  To add the record to the database, see L<"insert">.
60
61 Note that this stores the hash reference, not a distinct copy of the hash it
62 points to.  You can ask the object for a copy with the I<hash> method.
63
64 =cut
65
66 sub table { 'acct_snarf'; }
67
68 =item insert
69
70 Adds this record to the database.  If there is an error, returns the error,
71 otherwise returns false.
72
73 =cut
74
75 # the insert method can be inherited from FS::Record
76
77 =item delete
78
79 Delete this record from the database.
80
81 =cut
82
83 # the delete method can be inherited from FS::Record
84
85 =item replace OLD_RECORD
86
87 Replaces the OLD_RECORD with this one in the database.  If there is an error,
88 returns the error, otherwise returns false.
89
90 =cut
91
92 # the replace method can be inherited from FS::Record
93
94 =item check
95
96 Checks all fields to make sure this is a valid external mail account.  If
97 there is an error, returns the error, otherwise returns false.  Called by the
98 insert and replace methods.
99
100 =cut
101
102 sub check {
103   my $self = shift;
104   my $error =
105        $self->ut_numbern('snarfnum')
106     || $self->ut_textn('snarfname') #alphasn?
107     || $self->ut_number('svcnum')
108     || $self->ut_foreign_key('svcnum', 'svc_acct', 'svcnum')
109     || $self->ut_domain('machine')
110     || $self->ut_alphan('protocol')
111     || $self->ut_textn('username')
112     || $self->ut_numbern('check_freq')
113     || $self->ut_enum('leave', [ '', 'Y' ])
114     || $self->ut_enum('apop', [ '', 'Y' ])
115     || $self->ut_enum('tls', [ '', 'Y' ])
116     || $self->ut_alphan('mailbox')
117   ;
118   return $error if $error;
119
120   $self->_password =~ /^[^\t\n]*$/ or return "illegal password";
121   $self->_password($1);
122
123   ''; #no error
124 }
125
126 sub check_freq_labels {
127
128   tie my %hash, 'Tie::IxHash',
129     0 => 'Never',
130     60 => 'minute',
131     120 => '2 minutes',
132     180 => '3 minutes',
133     300 => '5 minutes',
134     600 => '10 minutes',
135     900 => '15 minutes',
136     1800 => '30 minutes',
137     3600 => 'hour',
138     7200 => '2 hours',
139     10800 => '3 hours',
140     21600 => '6 hours',
141     43200 => '12 hours',
142     86400 => 'day',
143     172800 => '2 days',
144     259200 => '3 days',
145     604800 => 'week',
146     1000000000 => 'Disabled',
147   ;
148
149   \%hash;
150 }
151
152 =back
153
154 =head1 BUGS
155
156 =head1 SEE ALSO
157
158 L<FS::Record>, schema.html from the base documentation.
159
160 =cut
161
162 1;
163