[Rt-commit] r4414 - in rt/branches/3.5-TESTING: lib/RT
kevinr at bestpractical.com
kevinr at bestpractical.com
Thu Jan 19 22:51:24 EST 2006
Author: kevinr
Date: Thu Jan 19 22:51:23 2006
New Revision: 4414
Modified:
rt/branches/3.5-TESTING/ (props changed)
rt/branches/3.5-TESTING/lib/RT/Attachment_Overlay.pm
Log:
r10390 at sad-girl-in-snow: kevinr | 2006-01-18 16:31:03 -0500
RT-Ticket: 7149
RT-Status: resolved
RT-Update: correspond
* Cleaned up attachment creation in lib/RT/Attachment_Overlay.pm (thanks to
Ruslan Zakirov)
Modified: rt/branches/3.5-TESTING/lib/RT/Attachment_Overlay.pm
==============================================================================
--- rt/branches/3.5-TESTING/lib/RT/Attachment_Overlay.pm (original)
+++ rt/branches/3.5-TESTING/lib/RT/Attachment_Overlay.pm Thu Jan 19 22:51:23 2006
@@ -125,14 +125,13 @@
Create a new attachment. Takes a paramhash:
'Attachment' Should be a single MIME body with optional subparts
- 'Parent' is an optional Parent RT::Attachment object
- 'TransactionId' is the mandatory id of the Transaction this attachment is associated with.;
+ 'Parent' is an optional id of the parent attachment
+ 'TransactionId' is the mandatory id of the transaction this attachment is associated with.;
=cut
sub Create {
my $self = shift;
- my ($id);
my %args = ( id => 0,
TransactionId => 0,
Parent => 0,
@@ -142,8 +141,8 @@
#For ease of reference
my $Attachment = $args{'Attachment'};
- #if we didn't specify a ticket, we need to bail
- if ( $args{'TransactionId'} == 0 ) {
+ #if we didn't specify a ticket, we need to bail
+ if ( $args{'TransactionId'} == 0 ) {
$RT::Logger->crit( "RT::Attachment->Create couldn't, as you didn't specify a transaction\n" );
return (0);
@@ -165,37 +164,35 @@
#Get the filename
- my $Filename = $Attachment->head->recommended_filename || eval {
- ${ $Attachment->head->{mail_hdr_hash}{'Content-Disposition'}[0] }
- =~ /^.*\bfilename="(.*)"$/ ? $1 : ''
- };
+ my $Filename = $Attachment->head->recommended_filename;
# If a message has no bodyhandle, that means that it has subparts (or appears to)
# and we should act accordingly.
unless ( defined $Attachment->bodyhandle ) {
- $id = $self->SUPER::Create(
+ my $id = $self->SUPER::Create(
TransactionId => $args{'TransactionId'},
Parent => 0,
ContentType => $Attachment->mime_type,
- Headers => $Attachment->head->as_string,
- MessageId => $MessageId,
- Subject => $Subject);
+ Headers => $Attachment->head->as_string,
+ MessageId => $MessageId,
+ Subject => $Subject
+ );
unless ($id) {
$RT::Logger->crit("Attachment insert failed - ".$RT::Handle->dbh->errstr);
-
}
foreach my $part ( $Attachment->parts ) {
my $SubAttachment = new RT::Attachment( $self->CurrentUser );
- $SubAttachment->Create(
+ my ($id) = $SubAttachment->Create(
TransactionId => $args{'TransactionId'},
Parent => $id,
Attachment => $part,
- ContentType => $Attachment->mime_type,
-
);
+ unless ($id) {
+ $RT::Logger->crit("Attachment insert failed - ".$RT::Handle->dbh->errstr);
+ }
}
return ($id);
}
@@ -203,17 +200,20 @@
#If it's not multipart
else {
- my ($ContentEncoding, $Body) = $self->_EncodeLOB($Attachment->bodyhandle->as_string, $Attachment->mime_type);
- my $id = $self->SUPER::Create( TransactionId => $args{'TransactionId'},
- ContentType => $Attachment->mime_type,
- ContentEncoding => $ContentEncoding,
- Parent => $args{'Parent'},
- Headers => $Attachment->head->as_string,
- Subject => $Subject,
- Content => $Body,
- Filename => $Filename,
- MessageId => $MessageId
- );
+ my ($ContentEncoding, $Body) = $self->_EncodeLOB( $Attachment->bodyhandle->as_string,
+ $Attachment->mime_type
+ );
+ my $id = $self->SUPER::Create(
+ TransactionId => $args{'TransactionId'},
+ ContentType => $Attachment->mime_type,
+ ContentEncoding => $ContentEncoding,
+ Parent => $args{'Parent'},
+ Headers => $Attachment->head->as_string,
+ Subject => $Subject,
+ Content => $Body,
+ Filename => $Filename,
+ MessageId => $MessageId,
+ );
unless ($id) {
$RT::Logger->crit("Attachment insert failed - ".$RT::Handle->dbh->errstr);
}
More information about the Rt-commit
mailing list