[Rt-commit] rt branch, create-action, updated. 0db7157d6068ab22bc89078386dd275d2639a642
sartak at bestpractical.com
sartak at bestpractical.com
Thu Nov 5 16:36:51 EST 2009
The branch, create-action has been updated
via 0db7157d6068ab22bc89078386dd275d2639a642 (commit)
from 243ee3458b5b6ae1d79a073cc30b0c1f7aab74aa (commit)
Summary of changes:
lib/RT/Interface/Email.pm | 83 ++++++++++++++++++++++++++++++++++++++++++
lib/RT/Interface/Web.pm | 87 +-------------------------------------------
lib/RT/Model/Ticket.pm | 3 +-
3 files changed, 86 insertions(+), 87 deletions(-)
- Log -----------------------------------------------------------------
commit 0db7157d6068ab22bc89078386dd275d2639a642
Author: Shawn M Moore <sartak at bestpractical.com>
Date: Thu Nov 5 16:36:42 2009 -0500
Move make_mime_entity to RT::Interface::Email
diff --git a/lib/RT/Interface/Email.pm b/lib/RT/Interface/Email.pm
index 80fa793..d0edcb6 100755
--- a/lib/RT/Interface/Email.pm
+++ b/lib/RT/Interface/Email.pm
@@ -1600,4 +1600,87 @@ sub is_correct_action {
return ( 1, @actions );
}
+=head2 make_mime_entity PARAMHASH
+
+Takes a paramhash subject, body and attachment_field_name.
+
+Also takes Form, cc and type as optional paramhash keys.
+
+ Returns a MIME::Entity.
+
+=cut
+
+sub make_mime_entity {
+
+ my %args = (
+ subject => undef,
+ from => undef,
+ cc => undef,
+ body => undef,
+ attachment_field_name => undef,
+ type => undef,
+ @_,
+ );
+ my $Message = MIME::Entity->build(
+ Type => 'multipart/mixed',
+ Subject => $args{'subject'} || "",
+ From => $args{'from'},
+ Cc => $args{'cc'},
+ );
+
+ if ( defined $args{'body'} && length $args{'body'} ) {
+
+ # Make the update content have no 'weird' newlines in it
+ $args{'body'} =~ s/\r\n/\n/gs;
+
+ # MIME::Head is not happy in utf-8 domain. This only happens
+ # when processing an incoming email (so far observed).
+ no utf8;
+ use bytes;
+ $Message->attach(
+ Type => $args{'type'} || 'text/plain',
+ Charset => 'UTF-8',
+ Data => $args{'body'},
+ );
+ }
+
+ if ( $args{'attachment_field_name'} ) {
+
+ my $cgi_object = Jifty->handler->cgi;
+
+ if ( my $filehandle = $cgi_object->upload( $args{'attachment_field_name'} ) ) {
+
+ my ( @content, $buffer );
+ while ( my $bytesread = read( $filehandle, $buffer, 4096 ) ) {
+ push @content, $buffer;
+ }
+
+ my $uploadinfo = $cgi_object->uploadInfo($filehandle);
+
+ # Prefer the cached name first over CGI.pm stringification.
+ my $filename = $RT::Mason::CGI::Filename;
+ $filename = "$filehandle" unless defined($filename);
+ $filename = Encode::decode_utf8($filename);
+ $filename =~ s{^.*[\\/]}{};
+
+ $Message->attach(
+ Type => $uploadinfo->{'Content-Type'},
+ Filename => $filename,
+ Data => \@content,
+ );
+ if ( !$args{'subject'}
+ && !( defined $args{'body'} && length $args{'body'} ) )
+ {
+ $Message->head->set( 'Subject' => $filename );
+ }
+ }
+ }
+
+ $Message->make_singlepart;
+ RT::I18N::set_mime_entity_to_utf8($Message); # convert text parts into utf-8
+
+ return ($Message);
+}
+
+
1;
diff --git a/lib/RT/Interface/Web.pm b/lib/RT/Interface/Web.pm
index 517a629..ff85eef 100755
--- a/lib/RT/Interface/Web.pm
+++ b/lib/RT/Interface/Web.pm
@@ -485,94 +485,11 @@ sub process_update_message {
return @results;
}
-
-
-=head2 make_mime_entity PARAMHASH
-
-Takes a paramhash subject, body and attachment_field_name.
-
-Also takes Form, cc and type as optional paramhash keys.
-
- Returns a MIME::Entity.
-
-=cut
-
+# Provided for back-compat
sub make_mime_entity {
-
- my %args = (
- subject => undef,
- from => undef,
- cc => undef,
- body => undef,
- attachment_field_name => undef,
- type => undef,
- @_,
- );
- my $Message = MIME::Entity->build(
- Type => 'multipart/mixed',
- Subject => $args{'subject'} || "",
- From => $args{'from'},
- Cc => $args{'cc'},
- );
-
- if ( defined $args{'body'} && length $args{'body'} ) {
-
- # Make the update content have no 'weird' newlines in it
- $args{'body'} =~ s/\r\n/\n/gs;
-
- # MIME::Head is not happy in utf-8 domain. This only happens
- # when processing an incoming email (so far observed).
- no utf8;
- use bytes;
- $Message->attach(
- Type => $args{'type'} || 'text/plain',
- Charset => 'UTF-8',
- Data => $args{'body'},
- );
- }
-
- if ( $args{'attachment_field_name'} ) {
-
- my $cgi_object = Jifty->handler->cgi;
-
- if ( my $filehandle = $cgi_object->upload( $args{'attachment_field_name'} ) ) {
-
- my ( @content, $buffer );
- while ( my $bytesread = read( $filehandle, $buffer, 4096 ) ) {
- push @content, $buffer;
- }
-
- my $uploadinfo = $cgi_object->uploadInfo($filehandle);
-
- # Prefer the cached name first over CGI.pm stringification.
- my $filename = $RT::Mason::CGI::Filename;
- $filename = "$filehandle" unless defined($filename);
- $filename = Encode::decode_utf8($filename);
- $filename =~ s{^.*[\\/]}{};
-
-
- $Message->attach(
- Type => $uploadinfo->{'Content-Type'},
- Filename => $filename,
- Data => \@content,
- );
- if ( !$args{'subject'}
- && !( defined $args{'body'} && length $args{'body'} ) )
- {
- $Message->head->set( 'Subject' => $filename );
- }
-
- }
- }
-
- $Message->make_singlepart;
- RT::I18N::set_mime_entity_to_utf8($Message); # convert text parts into utf-8
-
- return ($Message);
-
+ RT::Interface::Email::make_mime_entity(@_);
}
-
sub process_acl_changes {
my $ARGSref = shift;
diff --git a/lib/RT/Model/Ticket.pm b/lib/RT/Model/Ticket.pm
index 9b1a503..1517bc9 100755
--- a/lib/RT/Model/Ticket.pm
+++ b/lib/RT/Model/Ticket.pm
@@ -482,8 +482,7 @@ sub create {
current_user => $self->current_user,
);
- # XXX: move make_mime_entity somewhere sane
- $args{mime_obj} = HTML::Mason::Commands::make_mime_entity(
+ $args{mime_obj} = RT::Interface::Email::make_mime_entity(
subject => $args{'subject'},
from => $args{'from'},
cc => $args{'cc'},
-----------------------------------------------------------------------
More information about the Rt-commit
mailing list