15
|
1 |
#!/usr/bin/env ruby
|
|
2 |
#
|
|
3 |
# This script delivers a pile-o-test email to a local list.
|
|
4 |
#
|
|
5 |
# ** The list should first be configured to deliver to an additional
|
|
6 |
# Maildir. **
|
|
7 |
#
|
|
8 |
# After an initial delivery run, you can generate test replies.
|
|
9 |
#
|
|
10 |
|
|
11 |
require 'mail'
|
|
12 |
require 'faker'
|
|
13 |
require 'pathname'
|
|
14 |
|
|
15 |
abort "Usage: #{$0} send <listaddress> <message count>\n" +
|
|
16 |
" #{$0} reply </path/to/maildir> <message count>" if ARGV.size < 3
|
|
17 |
mode, list, count = ARGV
|
|
18 |
|
|
19 |
SENDERS = count.to_i.times.each_with_object( [] ) do |i, acc|
|
|
20 |
acc << "%s %s <%s>" % [
|
|
21 |
Faker::Name.first_name,
|
|
22 |
Faker::Name.last_name,
|
|
23 |
Faker::Internet.safe_email
|
|
24 |
]
|
|
25 |
end
|
|
26 |
|
|
27 |
SUBJECTS = count.to_i.times.each_with_object( [] ) do |i, acc|
|
|
28 |
intro = if rand(3).zero?
|
|
29 |
"%s %s" % [
|
|
30 |
[ 'Trying to', 'How do I', 'Help -' ].sample,
|
|
31 |
Faker::Hacker.verb
|
|
32 |
]
|
|
33 |
else
|
|
34 |
Faker::Hacker.ingverb.capitalize
|
|
35 |
end
|
|
36 |
acc << "%s %s %s %s%s" % [
|
|
37 |
intro,
|
|
38 |
( rand(2).zero? ? Faker::Hacker.noun : Faker::Hacker.abbreviation ),
|
|
39 |
[ 'for a', 'on', 'on the', 'with some' ].sample,
|
|
40 |
Faker::Hacker.noun,
|
|
41 |
[ '?', '.', '?????'].sample
|
|
42 |
]
|
|
43 |
end
|
|
44 |
|
|
45 |
Mail.defaults { delivery_method :sendmail }
|
|
46 |
|
|
47 |
case mode
|
|
48 |
when 'send'
|
|
49 |
until SENDERS.empty?
|
|
50 |
mail = Mail.new do
|
|
51 |
to list
|
|
52 |
from SENDERS.pop
|
|
53 |
subject SUBJECTS.pop
|
|
54 |
body Faker::Hacker.say_something_smart
|
|
55 |
end
|
|
56 |
mail.deliver
|
|
57 |
end
|
|
58 |
|
|
59 |
when 'reply'
|
|
60 |
maildir = Pathname.new( list ) + 'new'
|
|
61 |
abort "%s doesn't exist." unless maildir.exist?
|
|
62 |
|
|
63 |
count.to_i.times do
|
|
64 |
orig = Mail.read( maildir.children.sample.to_s )
|
|
65 |
mail = Mail.new do
|
|
66 |
to orig.to
|
|
67 |
from SENDERS.sample
|
|
68 |
subject "Re: %s" % [ orig.subject ]
|
|
69 |
body Faker::Hacker.say_something_smart
|
|
70 |
in_reply_to "<%s>" % [ orig.message_id ]
|
|
71 |
references "<%s>" % [ orig.message_id ]
|
|
72 |
end
|
|
73 |
mail.deliver
|
|
74 |
end
|
|
75 |
end
|
|
76 |
|