/[smecontribs]/rpms/smeserver-learn/contribs8/smeserver-learn-1.0-VERBOSE.patch
ViewVC logotype

Contents of /rpms/smeserver-learn/contribs8/smeserver-learn-1.0-VERBOSE.patch

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.1 - (show annotations) (download)
Thu Mar 17 06:22:11 2016 UTC (8 years, 7 months ago) by unnilennium
Branch: MAIN
CVS Tags: smeserver-learn-1_0-10_el5_sme, smeserver-learn-1_0-12_el5_sme, smeserver-learn-1_0-11_el5_sme, HEAD
* Wed Mar 16 2016 JP Pialasse <tests@pialasse.com> 1.0-10.sme
- fix encoding problem when removing or adding tags [SME: 9282]
- fix moving file not working MOVE patch [SME: 9314]
- NFR: setting for verbose (enabled,disabled, active) VERBOSE patch [SME: 9313]

1 diff -up smeserver-learn-1.0/root/etc/e-smith/db/configuration/defaults/Learn/Verbose.VERBOSE smeserver-learn-1.0/root/etc/e-smith/db/configuration/defaults/Learn/Verbose
2 --- smeserver-learn-1.0/root/etc/e-smith/db/configuration/defaults/Learn/Verbose.VERBOSE 2016-03-17 01:21:14.985000000 -0400
3 +++ smeserver-learn-1.0/root/etc/e-smith/db/configuration/defaults/Learn/Verbose 2016-03-17 01:21:36.424000000 -0400
4 @@ -0,0 +1 @@
5 +enabled
6 diff -up smeserver-learn-1.0/root/usr/bin/Learn.pl.VERBOSE smeserver-learn-1.0/root/usr/bin/Learn.pl
7 --- smeserver-learn-1.0/root/usr/bin/Learn.pl.VERBOSE 2016-03-17 01:20:18.570000000 -0400
8 +++ smeserver-learn-1.0/root/usr/bin/Learn.pl 2016-03-17 01:19:16.000000000 -0400
9 @@ -57,6 +57,15 @@ binmode(SADB);
10 my $md5 = Digest::MD5->new->addfile(SADB)->b64digest;
11 close(SADB);
12
13 +#Verbose mode
14 +my $verbose= $sadb->get_prop("Learn", "Verbose") || "enabled";
15 +my $outputfile=($verbose eq "disabled")? "/dev/null": '/tmp/LearnLog.txt';
16 +my $LOG;
17 +open ( $LOG, '+>', $outputfile) unless ($verbose eq "enabled");
18 +# select new filehandle
19 +select $LOG unless ($verbose eq "enabled");
20 +my $currentuser;
21 +
22 # Running for every user
23 foreach my $user (@users) {
24 my $firstname = $user->prop('FirstName');
25 @@ -68,9 +77,10 @@ foreach my $user (@users) {
26 next if ( defined @exclude and @found = grep { $_ eq $key } @exclude );
27 next unless ( ! defined @include or @found = grep { $_ eq $key } @include );
28
29 - printf("Checking for user (%s): %s %s\n", $key,$firstname, $lastname);
30 + $currentuser = sprintf("Checking for user (%s): %s %s\n", $key,$firstname, $lastname);
31 + print $currentuser unless ($verbose eq "active");
32
33 - my $MailDir = ($key eq "admin")? "/home/e-smith" . "/Maildir" : "/home/e-smith/files/users/" . $key . "/Maildir";
34 + my $MailDir = ($key eq "admin")? "/home/e-smith" . "/Maildir" : "/home/e-smith/files/users/" . $key . "/Maildir";
35
36 my @modes = ("LearnAsSpam","LearnAsHam","LearnInWL");
37 foreach my $mode (@modes) {
38 @@ -80,7 +90,7 @@ foreach my $user (@users) {
39 # getting dir name to search according to actual mode
40 my $dirname = $sadb->get_prop($mode, "dir");
41 if ( !(defined($dirname)) ) {
42 - print "Errors in DB, dir subkey not present for key $mode\n";
43 + Vact();print "Errors in DB, dir subkey not present for key $mode\n";
44 next;
45 }
46 # adding heading periode if missing as this is an IMAP folder
47 @@ -97,7 +107,7 @@ foreach my $user (@users) {
48 if (! @logdirs and ($sadb->get_prop($mode, "Uniq") eq "enabled")) {
49 ($login,$pass,$uid,$gid) = getpwnam($key)
50 or die "$key not in passwd file";
51 - print "+->mkdir :". $MailDir . "/" . $dirname . "\n";
52 + Vact();print "+->mkdir :". $MailDir . "/" . $dirname . "\n";
53 foreach $a ('','/cur','/tmp','/new'){
54 mkdir $MailDir . "/" . $dirname . "$a";
55 chown $uid,$gid,$MailDir . "/" . $dirname . "$a";
56 @@ -112,7 +122,7 @@ foreach my $user (@users) {
57 $a=(substr($a, 0, 1) eq '.')? $a: ".$a";
58 my $Link= $MailDir . "/" . $a;
59 if (! -e $Link) {
60 - print "+->create link $Link on $junkdir\n";
61 + Vact(); print "+->create link $Link on $junkdir\n";
62 symlink($junkdir, $Link) or die "Can't create symlink from $Link to $junkdir: $!";
63 };
64 }
65 @@ -123,7 +133,7 @@ foreach my $user (@users) {
66 if ($mode eq "LearnAsSpam" and $sadb->get_prop($mode, "DeleteAfterLearn") eq "enabled" and $DelayToMove >0) {
67 my $SpamDir = $MailDir . "/" . $logdir . "/cur/";
68 return unless (-e $SpamDir and -d $SpamDir);
69 - @files=();
70 + @files=();
71 find(\&wanted, $junkdir ."/cur" );
72 find(\&wanted, $junkdir ."/new" ) if ($sadb->get_prop($mode, "LearnNew") eq "enabled" or $sadb->get_prop($mode, "LearnNew") eq "junkmail");
73 sub wanted {
74 @@ -137,8 +147,8 @@ foreach my $user (@users) {
75 my %filehash=@files; #puts the array into a hash for easy printing. Key=file, Value=date
76 undef @files;
77 foreach $filename (sort keys %filehash){
78 - print "--> moving $filename $filehash{$filename}\n";
79 - move $filename,"$MailDir/$dirname/cur" ;
80 + Vact(); print "--> moving $filename $filehash{$filename}\n";
81 + move $filename,"$MailDir/$dirname/cur" ;
82 }
83 }
84
85 @@ -152,11 +162,11 @@ foreach my $user (@users) {
86 find( { wanted => sub { -f && $_ =~ m/($logdir\/cur|$logdir\/new|$logdir\/tmp)/ && $counter++;}, no_chdir => 1, follow_fast => 1 }, $SpamDir );
87 if ($mode eq "LearnAsSpam" and $counter>0) {
88 my $result = `/usr/bin/sa-learn --spam $SpamDir`;
89 - chomp($result); printf("+Learning Spam from %s: %s\n",$logdir,$result);
90 + chomp($result); Vact(); printf("+Learning Spam from %s: %s\n",$logdir,$result);
91 }
92 elsif ($mode eq "LearnAsHam" and $counter>0) {
93 my $result = `/usr/bin/sa-learn --ham $SpamDir`;
94 - chomp($result);printf("+Learning Ham from %s: %s\n",$logdir,$result);
95 + chomp($result); Vact(); printf("+Learning Ham from %s: %s\n",$logdir,$result);
96 }
97
98 @list= ($sadb->get_prop($mode, "LearnNew") eq "enabled") ? ('/cur/','/new/'):('/cur/');
99 @@ -176,7 +186,7 @@ foreach my $user (@users) {
100
101 #taking action according to actual mode
102 if ($mode eq "LearnInWL") {
103 - printf("+Learning in WhiteList: %s\n",$filetolearnbash);
104 + Vact(); printf("+Learning in WhiteList: %s\n",$filetolearnbash);
105 `/usr/bin/LearnInWL.pl $filetolearnbash`;
106 }
107 # if we are in LearnAsSpam mode and DeleteAfterLearn is enabled delete message, else tagging a move message
108 @@ -234,3 +244,21 @@ if ($newmd5 ne $md5) {
109 print "\n";
110 }
111
112 +# restore STDOUT
113 +select STDOUT;
114 +# read log and print on STDOUT if mode active
115 +if ($verbose eq "active"){
116 + seek $LOG, 0, 0;
117 + while (<$LOG>) {
118 + print $_;
119 + }
120 +}
121 +close($LOG) unless ($verbose eq "enabled");
122 +unlink $outputfile;
123 +
124 +# sub to print the user line if something happen on active verbose mode
125 +sub Vact() {
126 +return unless ($verbose eq "active");
127 +print $currentuser;
128 +$currentuser="";
129 +}

admin@koozali.org
ViewVC Help
Powered by ViewVC 1.2.1 RSS 2.0 feed