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