adding export to read mailbox status information, RT#15987
[freeside.git] / FS / FS / part_export / acct_sql_status.pm
1 package FS::part_export::acct_sql_status;
2 use base qw( FS::part_export::sql_Common );
3
4 use strict;
5 use warnings;
6 use vars qw( %info );
7
8 my $options = __PACKAGE__->sql_options;
9 delete $options->{$_} for qw( table schema static primary_key );
10
11 %info = (
12   'svc'      => 'svc_acct',
13   'options'  => $options,
14   'nodomain' => '',
15   'notes'    => <<END
16 Read mailbox status information (vacation and spam settings) from an SQL
17 database, tables "vacation" and "users" respectively.
18 END
19 );
20
21 sub rebless { shift; }
22
23 #don't want to inherit these from sql_Common
24 sub _export_insert    {}
25 sub _export_replace   {}
26 sub _export_delete    {}
27 sub _export_suspend   {}
28 sub _export_unsuspend {}
29
30 sub export_getstatus {
31   my($self, $svc_acct, $htmlref, $hashref) = @_;
32
33   my $dbh = DBI->connect( map $self->option($_), qw(datasrc username password) )
34     or do { $hashref->{'error'} = "can't connect: ".  $DBI::errstr; return; };
35
36   ###
37   #vacation settings
38   ###
39
40   my $vsth = $dbh->prepare('SELECT * FROM vacation WHERE email = ?')
41     or do { $hashref->{'error'} = "can't prepare: ". $dbh->errstr; return; };
42   $vsth->execute( $svc_acct->email )
43     or do { $hashref->{'error'} = "can't execute: ". $vsth->errstr; return; };
44
45   my $vrow = $vsth->fetchrow_hashref;
46   if ( $vrow ) {
47     $hashref->{'vacation_active'}  = $vrow->{'active'};
48     $hashref->{'vacation_subject'} = $vrow->{'subject'};
49     $hashref->{'vacation_body'}    = $vrow->{'body'};
50 #what about these?
51 #| cache   | text         | NO   |     | NULL                |       |
52 #| domain  | varchar(255) | NO   |     | NULL                |       |
53 #and disabling "Sender e-mail address for auto-reply message:", no place for it
54   }
55
56   ###
57   #spam settings
58   ###
59
60   my $ssth = $dbh->prepare('SELECT * FROM users WHERE address = ?')
61     or do { $hashref->{'error'} = "can't prepare: ". $dbh->errstr; return; };
62   $ssth->execute( $svc_acct->email )
63     or do { $hashref->{'error'} = "can't execute: ". $ssth->errstr; return; };
64
65   my $srow = $ssth->fetchrow_hashref;
66   if ( $srow ) {
67     $hashref->{'spam_tag_level'}     = $srow->{'spam_tag_level'};
68     $hashref->{'spam_tag2_level'}    = $srow->{'spam_tag2_level'};
69     $hashref->{'spam_kill_level'}    = $srow->{'spam_kill_level'};
70     $hashref->{'bypass_spam_checks'} = $srow->{'bypass_spam_checks'};
71     $hashref->{'spam_tag2_level'}    = $srow->{'spam_tag2_level'};
72   }
73
74   ###
75   # spam allow/deny list
76   ###
77
78   #my $lsth = $dbh->prepare('SELECT * FROM 
79
80   #htmlref not implemented/used for this status export
81
82 }
83
84 1;