+ return $sth->fetchall_arrayref({});
+}
+
+=head2 _add_attachements
+
+named parameters:
+letter - the standard letter hashref
+attachments - listref of attachments. each attachment is a hashref of:
+ type - the mime type, like 'text/plain'
+ content - the actual attachment
+ filename - the name of the attachment.
+message - a MIME::Lite object to attach these to.
+
+returns your letter object, with the content updated.
+
+=cut
+
+sub _add_attachments {
+ my $params = shift;
+
+ return unless 'HASH' eq ref $params;
+ foreach my $required_parameter (qw( letter attachments message )) {
+ return unless exists $params->{$required_parameter};
+ }
+ return $params->{'letter'} unless @{ $params->{'attachments'} };
+
+ # First, we have to put the body in as the first attachment
+ $params->{'message'}->attach(
+ Type => 'TEXT',
+ Data => $params->{'letter'}->{'content'},
+ );
+
+ foreach my $attachment ( @{ $params->{'attachments'} } ) {
+ $params->{'message'}->attach(
+ Type => $attachment->{'type'},
+ Data => $attachment->{'content'},
+ Filename => $attachment->{'filename'},
+ );
+ }
+ # we're forcing list context here to get the header, not the count back from grep.
+ ( $params->{'letter'}->{'content-type'} ) = grep( /^Content-Type:/, split( /\n/, $params->{'message'}->header_as_string ) );
+ $params->{'letter'}->{'content-type'} =~ s/^Content-Type:\s+//;
+ $params->{'letter'}->{'content'} = $params->{'message'}->body_as_string;
+
+ return $params->{'letter'};
+