public
Description: A clone of the CVS repository for fakemail
Homepage: http://sourceforge.net/projects/fakemail/
Clone URL: git://github.com/schapht/fakemail.git
Added support in perl and python scripts for --onlylog option which only 
logs that the email message was bound for a given recipient rather than 
storing the entire body of the message.  This is useful when fakemail is 
involved in a load test scenario.
schapht (author)
Fri Jun 06 10:47:24 -0700 2008
commit  4b8485d16e4a36c82b77614b7c9b65f8178ec02e
tree    5b70f6343f57d757458c7f19b81160f835cf3437
parent  fb47bba394902397795607996eeba6c2164dc4ec
...
15
16
17
 
18
19
20
...
23
24
25
 
26
27
28
...
93
94
95
96
97
98
99
100
 
 
 
 
 
 
 
 
 
101
102
103
...
15
16
17
18
19
20
21
...
24
25
26
27
28
29
30
...
95
96
97
 
 
 
 
 
98
99
100
101
102
103
104
105
106
107
108
109
0
@@ -15,6 +15,7 @@ GetOptions(
0
         'port=i' => \$port,
0
         'path=s' => \$path,
0
         'log=s' => \$log,
0
+ 'onlylog' => \$onlylog,
0
         'background' => \$background);
0
 
0
 if (! defined($host) or ! defined($port) or ! defined($path)) {
0
@@ -23,6 +24,7 @@ if (! defined($host) or ! defined($port) or ! defined($path)) {
0
             " --port=<port number>\n" .
0
             " --path=<path to save mails>\n" .
0
             " --log=<optional file to append messages to>\n" .
0
+ " --onlylog\n" .
0
             " --background\n";
0
 };
0
 $path =~ s|/$||;
0
@@ -93,11 +95,15 @@ serve();
0
         my $sender = $session->get_sender();
0
         my @recipients = $session->get_recipients();
0
         foreach my $recipient (@recipients) {
0
- message("Capturing mail to $recipient");
0
- open(FILE, "> " . get_filename_from_recipient($recipient));
0
- print FILE ${$data};
0
- close(FILE);
0
- message("Mail to $recipient saved");
0
+ if ($onlylog) {
0
+ message("Mail destined for $recipient");
0
+ } else {
0
+ message("Capturing mail to $recipient");
0
+ open(FILE, "> " . get_filename_from_recipient($recipient));
0
+ print FILE ${$data};
0
+ close(FILE);
0
+ message("Mail to $recipient saved");
0
+ }
0
         }
0
         message("Incoming mail dispatched");
0
         return (1, 250, "message queued");
...
25
26
27
28
29
30
31
32
33
34
35
36
 
 
 
 
 
 
 
 
 
 
 
 
37
38
39
...
45
46
47
 
48
49
50
...
58
59
60
61
 
62
63
64
...
80
81
82
83
 
84
85
86
 
87
88
89
...
101
102
103
 
 
104
105
106
...
25
26
27
 
 
 
 
 
 
 
 
 
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
...
48
49
50
51
52
53
54
...
62
63
64
 
65
66
67
68
...
84
85
86
 
87
88
89
 
90
91
92
93
...
105
106
107
108
109
110
111
112
0
@@ -25,15 +25,18 @@ class FakeServer(smtpd.SMTPServer):
0
     def process_message(self, peer, mailfrom, rcpttos, data):
0
         message("Incoming mail")
0
         for recipient in rcpttos:
0
- message("Capturing mail to %s" % recipient)
0
- count = self.RECIPIENT_COUNTER.get(recipient, 0) + 1
0
- self.RECIPIENT_COUNTER[recipient] = count
0
- filename = os.path.join(self.path, "%s.%s" % (recipient, count))
0
- filename = filename.replace("<", "").replace(">", "")
0
- f = file(filename, "w")
0
- f.write(data + "\n")
0
- f.close()
0
- message("Mail to %s saved" % recipient)
0
+ if onlylog:
0
+ message("Mail destined for %s" % recipient)
0
+ else:
0
+ message("Capturing mail to %s" % recipient)
0
+ count = self.RECIPIENT_COUNTER.get(recipient, 0) + 1
0
+ self.RECIPIENT_COUNTER[recipient] = count
0
+ filename = os.path.join(self.path, "%s.%s" % (recipient, count))
0
+ filename = filename.replace("<", "").replace(">", "")
0
+ f = file(filename, "w")
0
+ f.write(data + "\n")
0
+ f.close()
0
+ message("Mail to %s saved" % recipient)
0
         message("Incoming mail dispatched")
0
 
0
 
0
@@ -45,6 +48,7 @@ OPTIONS
0
         --port=<port number>
0
         --path=<path to save mails>
0
         --log=<optional file to append messages to>
0
+ --onlylog
0
         --background"""
0
 
0
 
0
@@ -58,7 +62,7 @@ def quit(reason=None):
0
 
0
 
0
 log_file = None
0
-
0
+onlylog = False
0
 
0
 def message(text):
0
     global log_file
0
@@ -80,10 +84,10 @@ def handle_signals():
0
 
0
 
0
 def read_command_line():
0
- global log_file
0
+ global log_file, onlylog
0
     try:
0
         optlist, args = getopt.getopt(sys.argv[1:], "",
0
- ["host=", "port=", "path=", "log=", "background"])
0
+ ["host=", "port=", "path=", "log=", "onlylog", "background"])
0
     except getopt.GetoptError:
0
         usage()
0
         sys.exit(2)
0
@@ -101,6 +105,8 @@ def read_command_line():
0
             path = arg
0
         elif opt == "--log":
0
             log_file = arg
0
+ elif opt == "--onlylog":
0
+ onlylog = True
0
         elif opt == "--background":
0
             background = True
0
     return host, port, path, background

Comments

    No one has commented yet.