delete fees, RT#81713
[freeside.git] / FS / FS / contact_email.pm
1 package FS::contact_email;
2 use base qw( FS::Record );
3
4 use strict;
5 use FS::Msgcat qw( gettext );
6
7 =head1 NAME
8
9 FS::contact_email - Object methods for contact_email records
10
11 =head1 SYNOPSIS
12
13   use FS::contact_email;
14
15   $record = new FS::contact_email \%hash;
16   $record = new FS::contact_email { 'column' => 'value' };
17
18   $error = $record->insert;
19
20   $error = $new_record->replace($old_record);
21
22   $error = $record->delete;
23
24   $error = $record->check;
25
26 =head1 DESCRIPTION
27
28 An FS::contact_email object represents a contact's email address.
29 FS::contact_email inherits from FS::Record.  The following fields are currently
30 supported:
31
32 =over 4
33
34 =item contactemailnum
35
36 primary key
37
38 =item contactnum
39
40 contactnum
41
42 =item emailaddress
43
44 emailaddress
45
46
47 =back
48
49 =head1 METHODS
50
51 =over 4
52
53 =item new HASHREF
54
55 Creates a new contact email address.  To add the email address to the database,
56 see L<"insert">.
57
58 Note that this stores the hash reference, not a distinct copy of the hash it
59 points to.  You can ask the object for a copy with the I<hash> method.
60
61 =cut
62
63 sub table { 'contact_email'; }
64
65 =item insert
66
67 Adds this record to the database.  If there is an error, returns the error,
68 otherwise returns false.
69
70 =item delete
71
72 Delete this record from the database.
73
74 =item replace OLD_RECORD
75
76 Replaces the OLD_RECORD with this one in the database.  If there is an error,
77 returns the error, otherwise returns false.
78
79 =item check
80
81 Checks all fields to make sure this is a valid email address.  If there is
82 an error, returns the error, otherwise returns false.  Called by the insert
83 and replace methods.
84
85 =cut
86
87 sub check {
88   my $self = shift;
89
90   my $error = 
91     $self->ut_numbern('contactemailnum')
92     || $self->ut_number('contactnum')
93   ;
94   return $error if $error;
95
96   #technically \w and also ! # $ % & ' * + - / = ? ^ _ ` { | } ~
97   # and even more technically need to deal with i18n addreesses soon
98   #  (maybe the UI can convert them for us ala punycode.js)
99   # but for now in practice have not encountered anything outside \w . - & + '
100   #  and even & and ' are super rare and probably have scarier "pass to shell"
101   #   implications than worth being pedantic about accepting
102   #    (we always String::ShellQuote quote them, but once passed...)
103   #                              SO: \w . - +
104   if ( $self->emailaddress =~ /^\s*([\w\.\-\+]+)\@(([\w\.\-]+\.)+\w+)\s*$/ ) {
105     my($user, $domain) = ($1, $2);
106     $self->emailaddress("$1\@$2");
107   } else {
108     return gettext("illegal_email_invoice_address"). ': '. $self->emailaddress;
109   }
110
111   $self->SUPER::check;
112 }
113
114 =back
115
116 =head1 BUGS
117
118 =head1 SEE ALSO
119
120 L<FS::contact>, L<FS::Record>
121
122 =cut
123
124 1;
125