add export to everyone.net outsource mail service
[freeside.git] / FS / FS / part_export / everyone_net.pm
1 package FS::part_export::everyone_net;
2
3 use vars qw(@ISA %info);
4 use Tie::IxHash;
5 use FS::part_export;
6
7 @ISA = qw(FS::part_export);
8
9 tie my %options, 'Tie::IxHash',
10   'clientID'  => { label=>'clientID' },
11   'password'  => { label=>'Password' },
12   #'workgroup' => { label=>'Default Workgroup' },
13 ;
14
15 %info = (
16   'svc'    => 'svc_acct',
17   'desc'   => 'Real-time export to Everyone.net outsourced mail service',
18   'options'=> \%options,
19   'notes'  => <<'END'
20 Real-time export to
21 <a href="http://www.cp.net/">Everyone.net</a> via the XRC Remote API.
22 Requires installation of
23 <a href="http://search.cpan.org/dist/Net-XRC">Net::XRC</a>
24 from CPAN.
25 END
26 );
27
28 sub rebless { shift; }
29
30 # experiement: want the status of these right away (don't want account to
31 # create or whatever and then get error in the queue from dup username or
32 # something), so no queueing
33
34 sub _export_insert {
35   my( $self, $svc_acct ) = (shift, shift);
36
37   eval "use Net::XRC qw(:types);";
38   return $@ if $@;
39
40   $self->_xrc_command( 'createUser',
41                        $svc_acct->domain,
42                        [],
43                        string($svc_acct->username),
44                        string($svc_acct->_password),
45                      );
46 }
47
48 sub _xrc_command {
49   my( $self, $method, $domain, @args ) = @_;
50   
51   eval "use Net::XRC qw(:types);";
52   return $@ if $@;
53
54   my $xrc = new Net::XRC (
55     'clientID' => $self->option('clientID'),
56     'password' => $self->option('password'),
57   );
58
59   my $dresponse = $xrc->lookupMXReadyClientIDByEmailDomain( string($domain) );
60   return $response->error unless $response->is_success;
61   my $clientID = $response->content;
62   return "clientID for domain $domain not found"
63     if $clientID == -1;
64
65   my $response = $xrc->$method($clientID, @args);
66   return $response->error unless $response->is_success;
67   '';
68
69 }
70
71 sub _export_replace {
72   my( $self, $new, $old ) = (shift, shift, shift);
73
74   eval "use Net::XRC qw(:types);";
75   return $@ if $@;
76
77   return "can't change domain with Everyone.net"
78     if $old->domain ne $new->domain;
79   return "can't change username with Everyone.net"
80     if $old->username ne $new->username;
81   return '' unless $old->_password ne $new->_password;
82
83   $self->_xrc_command( 'setUserPassword',
84                        $new->domain,
85                        $domain_clientID,
86                        string($new->username),
87                        string($new->_password),
88                      );
89 }
90
91 sub _export_delete {
92   my( $self, $svc_acct ) = (shift, shift);
93
94   eval "use Net::XRC qw(:types);";
95   return $@ if $@;
96
97   $self->_xrc_command( 'deleteUser',
98                        $svc_acct->domain,
99                        string($svc_acct->username),
100                      );
101 }
102
103 sub _export_suspend {
104   my( $self, $svc_acct ) = (shift, shift);
105
106   eval "use Net::XRC qw(:types);";
107   return $@ if $@;
108
109   $self->_xrc_command( 'suspendUser',
110                        $svc_acct->domain,
111                        $domain_clientID,
112                        string($svc_acct->username),
113                      );
114 }
115
116 sub _export_unsuspend {
117   my( $self, $svc_acct ) = (shift, shift);
118
119   eval "use Net::XRC qw(:types);";
120   return $@ if $@;
121
122   $self->_xrc_command( 'unsuspendUser',
123                        $svc_acct->domain,
124                        string($svc_acct->username),
125                      );
126 }
127
128 1;
129