[rt-commit] [svn] r605 - in rt/branches/rt-3.1: . lib/RT

jesse at fsck.com jesse at fsck.com
Fri Mar 19 01:56:11 EST 2004


Author: jesse
Date: Fri Mar 19 01:56:11 2004
New Revision: 605

Modified:
   rt/branches/rt-3.1/   (props changed)
   rt/branches/rt-3.1/lib/RT/Attachment_Overlay.pm
   rt/branches/rt-3.1/lib/RT/Record.pm
Log:
r1135 at tinbook:  jesse | 2004-03-19T06:55:24.031783Z

Factored out some attachment processing to ease future integration
----------------------------------------------------------------------


Modified: rt/branches/rt-3.1/lib/RT/Attachment_Overlay.pm
==============================================================================
--- rt/branches/rt-3.1/lib/RT/Attachment_Overlay.pm	(original)
+++ rt/branches/rt-3.1/lib/RT/Attachment_Overlay.pm	Fri Mar 19 01:56:11 2004
@@ -164,63 +164,11 @@
     #If it's not multipart
     else {
 
-        my $ContentEncoding = 'none';
 
         my $Body = $Attachment->bodyhandle->as_string;
 
-        #get the max attachment length from RT
-        my $MaxSize = $RT::MaxAttachmentSize;
 
-        #if the current attachment contains nulls and the 
-        #database doesn't support embedded nulls
-
-        if ( $RT::AlwaysUseBase64 or
-	     ( !$RT::Handle->BinarySafeBLOBs ) && ( $Body =~ /\x00/ ) ) {
-
-            # set a flag telling us to mimencode the attachment
-            $ContentEncoding = 'base64';
-
-            #cut the max attchment size by 25% (for mime-encoding overhead.
-            $RT::Logger->debug("Max size is $MaxSize\n");
-            $MaxSize = $MaxSize * 3 / 4;
-        # Some databases (postgres) can't handle non-utf8 data 
-        } elsif (    !$RT::Handle->BinarySafeBLOBs
-                  && $Attachment->mime_type !~ /text\/plain/gi
-                  && !Encode::is_utf8( $Body, 1 ) ) {
-              $ContentEncoding = 'quoted-printable';
-        }
-
-        #if the attachment is larger than the maximum size
-        if ( ($MaxSize) and ( $MaxSize < length($Body) ) ) {
-
-            # if we're supposed to truncate large attachments
-            if ($RT::TruncateLongAttachments) {
-
-                # truncate the attachment to that length.
-                $Body = substr( $Body, 0, $MaxSize );
-
-            }
-
-            # elsif we're supposed to drop large attachments on the floor,
-            elsif ($RT::DropLongAttachments) {
-
-                # drop the attachment on the floor
-                $RT::Logger->info( "$self: Dropped an attachment of size " . length($Body) . "\n" . "It started: " . substr( $Body, 0, 60 ) . "\n" );
-                return (undef);
-            }
-        }
-
-        # if we need to mimencode the attachment
-        if ( $ContentEncoding eq 'base64' ) {
-
-            # base64 encode the attachment
-            Encode::_utf8_off($Body);
-            $Body = MIME::Base64::encode_base64($Body);
-
-        } elsif ($ContentEncoding eq 'quoted-printable') {
-       	    Encode::_utf8_off($Body);
-            $Body = MIME::QuotedPrint::encode($Body);
-        }
+	my ($ContentEncoding, $Body) = $self->_EncodeLOB($Attachment->bodyhandle->as_string, $Attachment->mime_type);
 
 
         my $id = $self->SUPER::Create( TransactionId => $args{'TransactionId'},

Modified: rt/branches/rt-3.1/lib/RT/Record.pm
==============================================================================
--- rt/branches/rt-3.1/lib/RT/Record.pm	(original)
+++ rt/branches/rt-3.1/lib/RT/Record.pm	Fri Mar 19 01:56:11 2004
@@ -604,6 +604,79 @@
 
 }
 
+=head2 _EncodeLOB BODY MIME_TYPE
+
+Takes a potentially large attachment. Returns (ContentEncoding, EncodedBody) based on system configuration and selected database
+
+=cut
+
+sub _EncodeLOB {
+        my $self = shift;
+        my $Body = shift;
+        my $MIMEType = shift;
+
+        my $ContentEncoding = 'none';
+
+        #get the max attachment length from RT
+        my $MaxSize = $RT::MaxAttachmentSize;
+
+        #if the current attachment contains nulls and the
+        #database doesn't support embedded nulls
+
+        if ( $RT::AlwaysUseBase64 or
+             ( !$RT::Handle->BinarySafeBLOBs ) && ( $Body =~ /\x00/ ) ) {
+
+            # set a flag telling us to mimencode the attachment
+            $ContentEncoding = 'base64';
+
+            #cut the max attchment size by 25% (for mime-encoding overhead.
+            $RT::Logger->debug("Max size is $MaxSize\n");
+            $MaxSize = $MaxSize * 3 / 4;
+        # Some databases (postgres) can't handle non-utf8 data
+        } elsif (    !$RT::Handle->BinarySafeBLOBs
+                  && $MIMEType !~ /text\/plain/gi
+                  && !Encode::is_utf8( $Body, 1 ) ) {
+              $ContentEncoding = 'quoted-printable';
+        }
+
+        #if the attachment is larger than the maximum size
+        if ( ($MaxSize) and ( $MaxSize < length($Body) ) ) {
+
+            # if we're supposed to truncate large attachments
+            if ($RT::TruncateLongAttachments) {
+
+                # truncate the attachment to that length.
+                $Body = substr( $Body, 0, $MaxSize );
+
+            }
+
+            # elsif we're supposed to drop large attachments on the floor,
+            elsif ($RT::DropLongAttachments) {
+
+                # drop the attachment on the floor
+                $RT::Logger->info( "$self: Dropped an attachment of size " . length($Body) . "\n" . "It started: " . substr( $Body, 0, 60 ) . "\n" );
+                return ("none", "Large attachment dropped" );
+            }
+        }
+
+        # if we need to mimencode the attachment
+        if ( $ContentEncoding eq 'base64' ) {
+
+            # base64 encode the attachment
+            Encode::_utf8_off($Body);
+            $Body = MIME::Base64::encode_base64($Body);
+
+        } elsif ($ContentEncoding eq 'quoted-printable') {
+            Encode::_utf8_off($Body);
+            $Body = MIME::QuotedPrint::encode($Body);
+        }
+
+
+        return ($ContentEncoding, $Body);
+
+}
+
+
 
 eval "require RT::Record_Overlay";
 die $@ if ($@ && $@ !~ qr{^Can't locate RT/Record_Overlay.pm});



More information about the Rt-commit mailing list