Skip to Content.
Sympa Menu

en - Urlize patch for Sympa 3.1.1

Subject: The mailing list for listmasters using Sympa

List archive

Chronological Thread  
  • From: Pierre-Yves Vasener <address@concealed>
  • To: address@concealed
  • Subject: Urlize patch for Sympa 3.1.1
  • Date: Fri, 4 May 2001 11:36:06 +0200

Hello,

As I've already told you, I developped a patch which allows to replace big
attachements by url pointing to an archive of the attachement on the server.
This functionnality is customizeable for each list with two new parameters :
- urlize (0/1) : Activate/Desactivate the attachement substitution for the
list
- min_urlize_size (Kb) : Trigger value to activate the substitution.

So here is the patch for the v 3.1.1.
Hope you'll enjoy this new feature.

Regards.

--
Pierre-Yves Vasener - Ingénieur en informatique libre
E-mail : address@concealed
Alcôve, l'informatique est libre - http://www.alcove.com/
Tel. : +33.1.49.22.68.00
diff -Naur sympa-3.1.1/bin/Conf.pm sympa-3.1.1-patch/bin/Conf.pm
--- sympa-3.1.1/bin/Conf.pm Thu May 3 14:16:49 2001
+++ sympa-3.1.1-patch/bin/Conf.pm Thu May 3 14:16:28 2001
@@ -23,6 +23,7 @@
remind_return_path request_priority
rfc2369_header_fields sendmail sleep
sort sympa_priority syslog umask welcome_return_path
wwsympa_url
openssl trusted_ca_options key_passwd ssl_cert_dir
remove_headers
+ urlize min_urlize_size
);
my %valid_options = ();
map { $valid_options{$_}++; } @valid_options;
@@ -84,7 +85,9 @@
'loop_command_sampling_delay' => 3600,
'loop_command_decrease_factor' => 0.5,
'rfc2369_header_fields' =>
'help,subscribe,unsubscribe,post,owner,archive',
- 'remove_headers' =>
'Return-Receipt-To,Precedence,X-Sequence,Disposition-Notification-To'
+ 'remove_headers' =>
'Return-Receipt-To,Precedence,X-Sequence,Disposition-Notification-To',
+ 'urlize' => 1,
+ 'min_urlize_size' => 50000
);

%Conf = ();
diff -Naur sympa-3.1.1/bin/List.pm sympa-3.1.1-patch/bin/List.pm
--- sympa-3.1.1/bin/List.pm Thu May 3 14:16:50 2001
+++ sympa-3.1.1-patch/bin/List.pm Thu May 3 14:16:29 2001
@@ -657,7 +657,20 @@
'default' => {'conf' =>
'welcome_return_path'},
'title_id' => 85,
'group' => 'bounces'
- }
+ },
+ 'min_urlize_size' => {'format' => '\d+',
+ 'length' => 8,
+ 'unit' => 'bytes',
+ 'default' => {'conf' => 'min_urlize_size'},
+ 'title_id' => 86,
+ 'group' => 'tuning'
+ },
+ 'urlize' => {'format' => [0,1],
+ 'default' => 1,
+ 'title_id' => 87,
+ 'group' => 'other'
+ }
+
);

## This is the generic hash which keeps all lists in memory.
@@ -1400,6 +1413,13 @@
## xxxxxx Virer eventuelle signature S/MIME
}

+ my $msg_size = -s $msg_file;
+
+ my $min_urlize_size = $self->{'admin'}{'min_urlize_size'};
+ if (($msg->is_multipart) && ($self->{'admin'}{'urlize'}) && ($msg_size >
$min_urlize_size)) {
+ $msg = urlize_msg($self, $msg, $msg_file);
+ }
+
## Archives
my $msgtostore = $msg;
if ($encrypt eq 'smime_crypted'){
@@ -1546,7 +1566,7 @@


##Send message for normal reception mode
- my $total = smtp::mailto($msg, $from, $encrypt, $msg_file, @tabrcpt);
+ my $total = smtp::mailto($msg, $from, $encrypt, '_ALTERED_', @tabrcpt);

##Prepare and send message for notice reception mode
# my $notice_msg = $msg;
@@ -2116,6 +2136,14 @@
return shift->{'admin'}{'max_size'};
}

+sub get_min_urlize_size {
+ return shift->{'admin'}{'min_urlize_size'};
+}
+
+sub get_urlize {
+ return shift->{'admin'}{'urlize'};
+}
+
## Returns an array with the Reply-To data
sub get_reply_to {
return (shift->{'admin'}{'reply_to'});
@@ -3835,7 +3863,8 @@
if ($admin->{'custom_subject'});

push @result, sprintf Msg(9, 13, "Reception mode : %s\n"),
$self->available_reception_mode;
-
+ push @result, sprintf Msg(9, 14, "Urlize : %d\n"),
$admin->{'urlize'} if ($admin->{'urlize'});
+ push @result, sprintf Msg(9, 15, "Minimum Urlize size : %d\n"),
$admin->{'min_urlize_size'} if ($admin->{'min_urlize_size'});
push @result, "\n";

if (open FILE, "$self->{'name'}/info") {
@@ -5638,6 +5667,67 @@
my $self = shift;

return join ('
',@{$self->{'admin'}{'available_user_options'}{'reception'}});
+}
+
+sub urlize_msg {
+ my($self, $msg, $msg_file) = @_;
+ do_log('debug2', 'List::urlize_msg(%s, %s, %s)', $self->{'name'}, $msg,
$msg_file);
+
+ my $hdr = $msg->head;
+
+ my $parser = new MIME::Parser;
+ $parser->output_under("$self->{'name'}/archives");
+
+ my $parsed_msg = $parser->parse_open($msg_file);
+
+ my ($new_body, $part, $new_msg, $IO);
+
+ # Processes the parts of the original message to build the new body
+ foreach $part ($parsed_msg->parts) {
+ $new_body .= process_part($part, "$self->{'name'}/archives");
+ $new_body .= "\n\n";
+ }
+
+ $new_msg = build MIME::Entity Data => $new_body;
+
+ my $new_head = $new_msg->head;
+ pipe PIPEIN, PIPEOUT;
+ $msg->head->print(\*PIPEOUT);
+ close PIPEOUT;
+ $new_head->read(\*PIPEIN);
+ close PIPEIN;
+ $new_msg->head->replace('Content-type', 'text/plain');
+
+ open OUT, ">$msg_file";
+ $msg->print(\*OUT);
+ close OUT;
+ do_log('info', "Attachement(s) replaced by url(s) for message : %s",
$msg_file);
+ return $new_msg;
+}
+
+sub process_part {
+ my ($part, $dir) = shift;
+ my ($new_body, $IO);
+
+ # Get MIME type, and display accordingly...
+ my ($type, $subtype) = split('/', $part->head->mime_type);
+ my $body = $part->bodyhandle;
+ if ($type =~ /^(text|message)$/) { # text: display it...
+ if ($IO = $part->open("r")) {
+ $new_body .= $_ while (defined($_ = $IO->getline));
+ $IO->close;
+ } else {
+ do_log('info', "$0: couldn't find/open : $!");
+ }
+ } else { # binary: just summarize it...
+ my $path = $body->path;
+ my @split_path = split('/', $path);
+ my $file = $split_path[-1];
+ my $size = ($path ? (-s $path) : '???');
+ $new_body = "Attachement : $file ($size octets) :\n\n";
+ $new_body .= "$Conf{'wwsympa_url'}att/$path\n";
+ }
+ return $new_body;
}

#################################################################
diff -Naur sympa-3.1.1/bin/wwsympa.fcgi sympa-3.1.1-patch/bin/wwsympa.fcgi
--- sympa-3.1.1/bin/wwsympa.fcgi Thu May 3 14:16:51 2001
+++ sympa-3.1.1-patch/bin/wwsympa.fcgi Thu May 3 14:16:30 2001
@@ -4429,6 +4429,12 @@
$p->{'may_edit'} = $list->may_edit($pname,$param->{'user'}{'email'});
$p->{'changed'} = $::changed_params{$pname};

+ if ($pname eq 'urlize') {
+ $p->{'title'} = "Substituing attachments by links";
+ } elsif ($pname eq 'min_urlize_size') {
+ $p->{'title'} = "Minimal size pour the attachment substitution";
+ }
+
## Exceptions...too many
if ($pname eq 'topics') {
$p->{'type'} = 'enum';



Archive powered by MHonArc 2.6.19+.

Top of Page