Added GetPassword routine
[clearscm.git] / maps / bin / nuke
1 #!/usr/bin/perl
2 ################################################################################
3 #
4 # File:         $RCSfile: nuke,v $
5 # Revision:     $Revision: 1.1 $
6 # Description:  Displays list of email addresses based on report type.
7 # Author:       Andrew@DeFaria.com
8 # Created:      Fri Nov 29 14:17:21  2002
9 # Modified:     $Date: 2013/06/12 14:05:47 $
10 # Language:     perl
11 #
12 # (c) Copyright 2000-2006, Andrew@DeFaria.com, all rights reserved.
13 #
14 ################################################################################
15 use strict;
16 use warnings;
17
18 use FindBin;
19
20 use lib $FinBin::Bin, '/opt/clearscm/lib';
21
22 use MAPS;
23
24 use Display;
25
26 # Just me
27 my $userid = "andrew";
28
29 sub GetMailLoops {
30   my $type = "mailloop";
31
32   my @emails;
33
34   # Hack: ReturnEmails normally wants a start and end range of what
35   # emails to get. We really want all of them so let's just use 10000.
36   @emails = ReturnEmails $userid, $type, 0, 10000;
37
38   my %senders;
39
40   foreach (@emails) {
41     my $sender = shift @{$_};
42     my @msgs = @{$_};
43     my ($pattern, $domain) = split (/@/, $sender);
44
45     if (scalar @msgs > 0) {
46       $senders{$domain} = scalar @msgs;
47     } # if
48   } # foreach
49
50   return %senders;
51 } # GetMailLoops
52
53 sub Add2List {
54   my $type      = shift;
55   my @items     = @_;
56
57   my $sender    = "";
58   my $nextseq   = MAPSDB::GetNextSequenceNo $userid, $type;
59
60   foreach (@items) {
61     my $domain = "\@$_";
62
63     display_nolf "Adding $domain to null list ($nextseq)...";
64
65     if (OnNulllist $domain) {
66       display_nolf " Already on list";
67       DeleteLog $domain;
68       display " - cleaned";
69     } else {
70       Add2Nulllist $domain, $userid, "";
71       display " done";
72         
73       # Now remove this entry from the other lists (if present)
74       foreach my $otherlist ("white", "black") {
75         my $sth = FindList $otherlist, $domain;
76         my ($sequence, $count);
77         ($_, $_, $_, $_, $_, $sequence) = GetList $sth;
78         if (defined $sequence) {
79           $count = DeleteList $otherlist, $sequence;
80         } # if
81       } # foreach
82     } # if
83     $nextseq++;
84   } # while
85 } # Add2List
86
87 # Main
88
89 # Set no output buffering
90 $| = 1;
91
92 # Let's be nice
93 setpriority 0, 0, 10;
94
95 SetContext $userid;
96
97 my %senders = GetMailLoops;
98
99 foreach (sort (keys (%senders))) {
100   print "\@$_\n";
101 } # foreach
102
103 if (scalar keys (%senders) eq 0) {
104   display "No mailloops detected";
105   exit 0;
106 } # if
107
108 print "Nuke these domains? ";
109 $_ = <STDIN>;
110
111 if (/y/i) {
112   Add2List "null", (sort (keys (%senders)));
113 } # if
114
115 exit;