3 package RT::Extension::MessageSizeLimit;
9 RT-Extension-MessageSizeLimit - Force web message size limit on ticket create/update
13 This RT extension enforces a certain message size limit when a user create a
14 ticket or make a comment/correspondance on it.
16 It uses a guess of outgoing mail size based on subject/content/attachments. It
17 may miss a few bytes from mail headers, templates contents.
19 You would typically set the limit a little bit lower than your outgoing MTA
22 See the configuration example under L</INSTALLATION>.
28 =item C<perl Makefile.PL>
34 May need root permissions
36 =item Edit your F</opt/rt4/etc/RT_SiteConfig.pm>
38 If you are using RT 4.2 or greater, add this line:
40 Plugin('RT::Extension::MessageSizeLimit');
42 For RT 4.0, add this line:
44 Set(@Plugins, qw(RT::Extension::MessageSizeLimit));
46 or add C<RT::Extension::MessageSizeLimit> to your existing C<@Plugins> line.
48 Then configure the limit (default 9MB) using the C<$MessageSizeLimit>
49 config option. This option takes the generic form of:
51 Set( $MessageSizeLimit, BYTES );
53 =item Clear your mason cache
55 rm -rf /opt/rt4/var/mason_data/obj
57 =item Restart your webserver
61 =head1 IMPLEMENTATION DETAILS
67 Take BYTES, returns a basic human readable representation of it.
74 if ( $bytes >= 1000 * 1000 * 1000 ) {
75 return sprintf("%0.2f%s", $bytes / 1000 / 1000 / 1000, "GB");
76 } elsif ( $bytes >= 1000 * 1000 ) {
77 return sprintf("%0.2f%s", $bytes / 1000 / 1000, "MB");
78 } elsif ( $bytes >= 1000 ) {
79 return sprintf("%0.2f%s", $bytes / 1000, "kB");
81 return sprintf("%0.2f%s", $bytes, "B");
85 =head3 CheckMessageSizeLimit
87 This is the main routine, it takes args from RT callbacks and validate message size.
89 Returns undef if size isn't exceeded, localized error message if it has been exceeded.
93 sub CheckMessageSizeLimit {
102 my $max_size = RT->Config->Get('MessageSizeLimit') || 9 * 1000 * 1000;
105 # Compute subject size
106 $size += length($args{Subject});
109 $size += length($args{Content});
111 # Add attachments sizes if any
112 foreach my $file_name ( keys %{$args{'Attachments'}} ) {
113 my $attach_size = length($args{'Attachments'}{$file_name}->as_string);
115 RT->Logger->debug("Attachment size: $attach_size B");
116 $size += $attach_size;
119 RT->Logger->debug("Message size: $size");
121 if ( $size && $size > $max_size ) {
122 RT->Logger->info("Message size limit exceeded: $size / $max_size");
123 return $args{'CurrentUser'}->loc("Message size limit exceeded"). " (".BytesToHuman($size)." / ".BytesToHuman($max_size)."), ".$args{'CurrentUser'}->loc("please reduce message size or remove attachments");
134 =item Dynamic enforcement using javascript
136 =item Allow translation of size units
142 Emmanuel Lacour, E<lt>elacour@home-dn.netE<gt>
146 All bugs should be reported via email to
148 L<bug-RT-Extension-MessageSizeLimit@rt.cpan.org|mailto:bug-RT-Extension-MessageSizeLimit@rt.cpan.org>
152 L<rt.cpan.org|http://rt.cpan.org/Public/Dist/Display.html?Name=RT-Extension-MessageSizeLimit>.
154 =head1 LICENSE AND COPYRIGHT
156 This software is Copyright (c) 2016 by Emmanuel Lacour <elacour@home-dn.net>
158 This is free software, licensed under:
160 The GNU General Public License, Version 2, June 1991