4 use base qw( FS::cust_main_Mixin FS::Record );
5 use FS::Record qw( qsearch qsearchs );
7 use vars qw( @statuses );
11 FS::cust_msg - Object methods for cust_msg records
17 $record = new FS::cust_msg \%hash;
18 $record = new FS::cust_msg { 'column' => 'value' };
20 $error = $record->insert;
22 $error = $record->check;
26 An FS::cust_msg object represents an email message generated by Freeside
27 and sent to a customer (see L<FS::msg_template>). FS::cust_msg inherits
28 from FS::Record. The following fields are currently supported:
32 =item custmsgnum - primary key
34 =item custnum - customer number
36 =item msgnum - template number
38 =item msgtype - the message type
40 =item _date - the time the message was sent
42 =item env_from - envelope From address
44 =item env_to - envelope To addresses, including Bcc, separated by newlines
46 =item header - message header
48 =item body - message body
50 =item error - Email::Sender error message (or null for success)
64 # the new method can be inherited from FS::Record, if a table method is defined
66 sub table { 'cust_msg'; }
68 sub nohistory_fields { ('header', 'body'); }
69 # history is kind of pointless on this table
71 @statuses = qw( prepared sent failed );
75 Adds this record to the database. If there is an error, returns the error
76 and emits a warning; otherwise returns false.
81 # warn of all errors here; failing to insert/update one of these should
82 # cause a warning at worst
84 my $error = $self->SUPER::insert;
85 warn "[cust_msg] error logging message status: $error\n" if $error;
91 Delete this record from the database. There's no reason to do this.
97 warn "[cust_msg] log entry deleted\n";
98 return $self->SUPER::delete;
101 =item replace OLD_RECORD
103 Replaces the OLD_RECORD with this one in the database. If there is an error,
104 returns the error and emits a warning, otherwise returns false.
110 my $error = $self->SUPER::replace(@_);
111 warn "[cust_msg] error logging message status: $error\n" if $error;
117 Checks all fields to make sure this is a valid example. If there is
118 an error, returns the error, otherwise returns false. Called by the insert
123 # the check method should currently be supplied - FS::Record contains some
124 # data checking routines
130 $self->ut_numbern('custmsgnum')
131 || $self->ut_numbern('custnum')
132 || $self->ut_foreign_keyn('custnum', 'cust_main', 'custnum')
133 || $self->ut_numbern('msgnum')
134 || $self->ut_foreign_keyn('msgnum', 'msg_template', 'msgnum')
135 || $self->ut_numbern('_date')
136 || $self->ut_textn('env_from')
137 || $self->ut_textn('env_to')
138 || $self->ut_anything('header')
139 || $self->ut_anything('body')
140 || $self->ut_enum('status', \@statuses)
141 || $self->ut_textn('error')
142 || $self->ut_enum('msgtype', [ '',
149 return $error if $error;
156 Returns the complete message as a L<MIME::Entity>.
160 Returns a list of the MIME parts contained in the message, as L<MIME::Entity>
167 if ( !exists($self->{entity}) ) {
168 my $parser = MIME::Parser->new;
169 my $output_dir = "$FS::UID::cache_dir/cache.$FS::UID::datasrc/mimeparts";
170 mkdir($output_dir) unless -d $output_dir;
171 $parser->output_under($output_dir);
173 $parser->parse_data( $self->header . "\n" . $self->body );
180 # return only the parts with bodies, not the multipart containers
181 grep { $_->bodyhandle } $self->entity->parts_DFS;
188 L<FS::msg_template>, L<FS::cust_main>, L<FS::Record>.