summaryrefslogtreecommitdiff
path: root/FS/FS/part_export/acct_sql_status.pm
blob: 0e734315181d62c82ef0f5a3c8c68216916b0f52 (plain)
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
package FS::part_export::acct_sql_status;
use base qw( FS::part_export::sql_Common );

use strict;
use warnings;
use vars qw( %info );
use Tie::IxHash;
use FS::DBI;

tie my %options, 'Tie::IxHash', %{__PACKAGE__->sql_options};
delete $options{$_} for qw( table schema static primary_key );

%info = (
  'svc'      => 'svc_acct',
  'desc'     => 'Mailbox status information from SQL',
  'options'  => \%options,
  'nodomain' => '',
  'no_machine' => 1,
  'notes'    => <<END
Read mailbox status information (vacation and spam settings) from an SQL
database, tables "vacation" and "users" respectively.
END
);

sub rebless { shift; }

#don't want to inherit these from sql_Common
sub _export_insert    {}
sub _export_replace   {}
sub _export_delete    {}
sub _export_suspend   {}
sub _export_unsuspend {}

sub export_getstatus {
  my($self, $svc_acct, $htmlref, $hashref) = @_;

  my $dbh = FS::DBI->connect( map $self->option($_), qw(datasrc username password) )
    or return "can't connect: ".  $FS::DBI::errstr;

  ###
  #vacation settings
  ###

  my $vsth = $dbh->prepare('SELECT * FROM vacation WHERE email = ?')
    or return "can't prepare: ". $dbh->errstr;
  $vsth->execute( $svc_acct->email )
    or return "can't execute: ". $vsth->errstr;

  my $vrow = $vsth->fetchrow_hashref;
  if ( $vrow ) {
    $hashref->{'vacation_active'}  = $vrow->{'active'};
    $hashref->{'vacation_subject'} = $vrow->{'subject'};
    $hashref->{'vacation_body'}    = $vrow->{'body'};
#what about these?
#| cache   | text         | NO   |     | NULL                |       |
#| domain  | varchar(255) | NO   |     | NULL                |       |
#and disabling "Sender e-mail address for auto-reply message:", no place for it
  }

  ###
  #spam settings
  ###

  my $ssth = $dbh->prepare('SELECT * FROM users WHERE address = ?')
    or return "can't prepare: ". $dbh->errstr;
  $ssth->execute( $svc_acct->email )
    or return "can't execute: ". $ssth->errstr;

  my $srow = $ssth->fetchrow_hashref;
  if ( $srow ) {
    $hashref->{'spam_tag_level'}     = $srow->{'spam_tag_level'};
    $hashref->{'spam_tag2_level'}    = $srow->{'spam_tag2_level'};
    $hashref->{'spam_kill_level'}    = $srow->{'spam_kill_level'};
    $hashref->{'bypass_spam_checks'} = $srow->{'bypass_spam_checks'};
    $hashref->{'spam_tag2_level'}    = $srow->{'spam_tag2_level'};
  }

  ###
  # spam allow/deny list
  ###

  #my $lsth = $dbh->prepare('SELECT * FROM 

  #htmlref not implemented/used for this status export


  ''; #no errors

}

1;