Skip to content

Instantly share code, notes, and snippets.

@tdegrunt
Last active July 2, 2021 10:30
Show Gist options
  • Save tdegrunt/bb2c71edb2adf5e52f0c0d09a705d1ab to your computer and use it in GitHub Desktop.
Save tdegrunt/bb2c71edb2adf5e52f0c0d09a705d1ab to your computer and use it in GitHub Desktop.
Generating sample mbox for IMAPtest
require 'mail'
require 'securerandom'
size_distribution = {
10 => (0..19),
80 => (20..39),
150 => (40..59),
250 => (60..79),
15_000 => (80..100)
}
def generate_mail(f, size)
mail = Mail.new do
date Time.now
from '[email protected]'
to '[email protected]'
message_id '<[email protected]>'
body SecureRandom.urlsafe_base64(1024 * size)
end
f.puts "From #{mail.from.first} #{mail.date.rfc2822}"
f.puts "#{mail}\n"
end
if ARGV.size == 0
puts "generatesamplembox <filename> <nrofmails>"
exit
end
File.open(ARGV[0], 'w') do |f|
ARGV[1].to_i.times do |_t|
rnd_nr = (rand * 100).to_i
k, _v = size_distribution.find { |_k, v| v.cover? rnd_nr }
puts "Generating mail of #{k}kb"
generate_mail(f, k)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment