Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Richard Schneeman committed Aug 4, 2009
0 parents commit d11a34e
Show file tree
Hide file tree
Showing 13 changed files with 245 additions and 0 deletions.
20 changes: 20 additions & 0 deletions MIT-LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Copyright (c) 2009 [name of plugin creator]

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
42 changes: 42 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
MailFactory
======

mailfactory is tool for generating a mail object that you can use to test your apps email parsing behavior.

install
=======
script/plugin install git://github.com/thinkbohemian/MailFactory.git


Example
=======

mail = mail_factory(:from_email => from_email , :to_email => to_email , :subject => subject, :body => body)

If you want to simulate receiving an email from "foobar@example.com", sent to "you@example.com" with a subject of "my cool subject" and a body of "this is only a test" you could create the object like this:

mail_factory(:from_email => "foobar@example.com" , :to_email => "you@example.com" , :subject => "my cool subject", :body => "this is only a test")

If you don't care about some fields, mail factory will auto generate them for you.

mail = mail_factory


TMail::Mail.parse(mail).to.to_s
=> "foo@example.com"

TMail::Mail.parse(mail).from.to_s
=> "example@example.com"

TMail::Mail.parse(mail).subject.to_s
=>"testing testing"

TMail::Mail.parse(mail).body.to_s
=>"This is a test body. Pretty generic really, should make it past most filters\n"

=======

I created this to help test out my rails application http://www.WhySpam.Me its a new spin on sticking it to the man (the one spam-ing you all the time), if you want to fight back against spam, or just want to check out my site i would appreciate the visit. WhySpam is a creative commons licensed open source project, help out at: http://github.com/thinkbohemian/WhySpam/tree/master


Copyright (c) 2009 [Richard Schneeman || www.thinkbohemian.com ], released under the MIT license
23 changes: 23 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'

desc 'Default: run unit tests.'
task :default => :test

desc 'Test the MailFactory plugin.'
Rake::TestTask.new(:test) do |t|
t.libs << 'lib'
t.libs << 'test'
t.pattern = 'test/**/*_test.rb'
t.verbose = true
end

desc 'Generate documentation for the mailfactory plugin.'
Rake::RDocTask.new(:rdoc) do |rdoc|
rdoc.rdoc_dir = 'rdoc'
rdoc.title = 'mailfactory'
rdoc.options << '--line-numbers' << '--inline-source'
rdoc.rdoc_files.include('README')
rdoc.rdoc_files.include('lib/**/*.rb')
end
3 changes: 3 additions & 0 deletions init.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Include hook code here

require 'mailfactory'
1 change: 1 addition & 0 deletions install.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Install hook code here
29 changes: 29 additions & 0 deletions lib/mail_factory.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
module MailFactory
TEMPLATES_PATH = File.dirname(__FILE__) + '/templates'
CHARSET = "utf-8"

def mail_factory(mail_hash = { })
temp_string = IO.read("#{MailFactory::TEMPLATES_PATH}/emails/template_email")
mail_hash[:from_email] ||= "example@example.com"
mail_hash[:to_email] ||= "foo@example.com"
mail_hash[:subject] ||= "testing testing"
mail_hash[:body] ||= "This is a test body. Pretty generic really, should make it past most filters"
temp_string = temp_string.gsub(/xxxfrom_emailxxx/, mail_hash[:from_email])
temp_string = temp_string.gsub(/xxxto_emailxxx/, mail_hash[:to_email] )
temp_string = temp_string.gsub(/xxxsubjectxxx/, mail_hash[:subject] )
temp_string = temp_string.gsub(/xxxbodyxxx/, mail_hash[:body] )
end


# def mail_factory(from_email, to_email, subject, body)
# temp_string = IO.read("#{MailFactory::TEMPLATES_PATH}/emails/template_email")
# from_email = "example@example.com" if from_email.nil? || from_email == ""
# to_email = "foo@example.com" if to_email.nil? || to_email == ""
# subject = "testing testing" if subject.nil? || subject == ""
# body = "This is a test body. Pretty generic really, should make it past most filters" if body.nil? || body == ""
# temp_string = temp_string.gsub(/xxxfrom_emailxxx/, from_email )
# temp_string = temp_string.gsub(/xxxto_emailxxx/, to_email )
# temp_string = temp_string.gsub(/xxxsubjectxxx/, subject )
# temp_string = temp_string.gsub(/xxxbodyxxx/, body )
# end
end
1 change: 1 addition & 0 deletions lib/mailfactory.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include MailFactory
41 changes: 41 additions & 0 deletions lib/templates/emails/template_email
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
Return-Path: <xxxfrom_emailxxx>
X-Original-To: xxxto_emailxxx
Delivered-To: xxxto_emailxxx
Received: from mail-yx0-f197.google.com (mail-yx0-f197.google.com [209.85.210.197])
by mail.whyspam.me (Postfix) with ESMTP id D7060118174
for <xxxto_emailxxx>; Mon, 29 Jun 2009 03:29:21 +0000 (UTC)
Received: by yxe35 with SMTP id 35so5578549yxe.21
for <xxxto_emailxxx>; Sun, 28 Jun 2009 20:29:21 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=gamma;
h=domainkey-signature:received:received:message-id:from:to
:content-type:content-transfer-encoding:mime-version:subject:date
:x-mailer;
bh=ELY0hDvCjESXtTMGXmcGcOKSEdT9ID2tbb3A1gKI4OA=;
b=i1ro7urT3bSla2Cbo1O8iS9gWt/cRDYZwspcaF7Uu6wyFT5zWaRUMTtANCzKTBKWYa
A01U++BiFFfBb8HRxGYhEMDHlt6Dtw0AXUnnTPkPkB3PLxwbQ0swoLLsEYoHvN0+vlsQ
yxzpCoq2Cm1xgs/aK9b0UQARR/EM5KyXMHwiM=
DomainKey-Signature: a=rsa-sha1; c=nofws;
d=gmail.com; s=gamma;
h=message-id:from:to:content-type:content-transfer-encoding
:mime-version:subject:date:x-mailer;
b=SmQyauLdBknfLPpMWFnvWgBBZCO+aJljvaGU6XVTvO2lYxaED2NTJopbFghf7HwFos
e1XVrBTPExwzKT+2ITuLjiv6XkpVQDm14i+mQwWyomVQqQXurQ/qzqMz8FyM+1stskb0
Wp3bT/Ta7mRFDjeIMNo3q1pJUrBBStD8omHZU=
Received: by 10.90.75.9 with SMTP id x9mr5828240aga.59.1246246161214;
Sun, 28 Jun 2009 20:29:21 -0700 (PDT)
Received: from new-host.linksys ([70.114.144.26])
by mx.google.com with ESMTPS id 20sm7550930agd.23.2009.06.28.20.29.20
(version=TLSv1/SSLv3 cipher=RC4-MD5);
Sun, 28 Jun 2009 20:29:20 -0700 (PDT)
Message-Id: <51018298-B7F4-4189-B419-F6957DC598D8@gmail.com>
From: Richard Schneeman <xxxfrom_emailxxx>
To: xxxto_emailxxx
Content-Type: text/plain; charset=US-ASCII; format=flowed
Content-Transfer-Encoding: 7bit
Mime-Version: 1.0 (Apple Message framework v935.3)
Subject: xxxsubjectxxx
Date: Sun, 28 Jun 2009 22:29:19 -0500
X-Mailer: Apple Mail (2.935.3)

xxxbodyxxx
27 changes: 27 additions & 0 deletions mailfactory.tmproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>documents</key>
<array>
<dict>
<key>name</key>
<string>MailFactory</string>
<key>regexFolderFilter</key>
<string>!.*/(\.[^/]*|CVS|_darcs|_MTN|\{arch\}|blib|.*~\.nib|.*\.(framework|app|pbproj|pbxproj|xcode(proj)?|bundle))$</string>
<key>selected</key>
<true/>
<key>sourceDirectory</key>
<string></string>
</dict>
</array>
<key>fileHierarchyDrawerWidth</key>
<integer>302</integer>
<key>metaData</key>
<dict/>
<key>showFileHierarchyDrawer</key>
<true/>
<key>windowFrame</key>
<string>{{451, 286}, {920, 331}}</string>
</dict>
</plist>
Empty file added tasks/yaffle_tasks.rake
Empty file.
51 changes: 51 additions & 0 deletions test/mailfactory_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@

require File.dirname(__FILE__) + '/test_helper.rb'

class MailFactoryTest < Test::Unit::TestCase
# Replace this with your real tests.
def test_true
assert true
end

def test_default_mail_factory
mail = mail_factory
assert_equal "foo@example.com", TMail::Mail.parse(mail).to.to_s
assert_equal "example@example.com", TMail::Mail.parse(mail).from.to_s
assert_equal "testing testing", TMail::Mail.parse(mail).subject.to_s
assert_equal "This is a test body. Pretty generic really, should make it past most filters\n", TMail::Mail.parse(mail).body.to_s
end

def test_substitution_values
to_email = "blah@exmaple.com"
from_email = "wazzah@example.com"
subject = "dis is a subject"
body = "Ahhhnnnald has nahhhthiiing on dis body"
mail = mail_factory(:from_email => from_email , :to_email => to_email , :subject => subject, :body => body)
assert_equal to_email , TMail::Mail.parse(mail).to.to_s
assert_equal from_email, TMail::Mail.parse(mail).from.to_s
assert_equal subject, TMail::Mail.parse(mail).subject.to_s
assert_equal body+"\n", TMail::Mail.parse(mail).body.to_s
end
# def test_default_mail_factory
# mail = mail_factory("","","","")
# assert_equal "foo@example.com", TMail::Mail.parse(mail).to.to_s
# assert_equal "example@example.com", TMail::Mail.parse(mail).from.to_s
# assert_equal "testing testing", TMail::Mail.parse(mail).subject.to_s
# assert_equal "This is a test body. Pretty generic really, should make it past most filters\n", TMail::Mail.parse(mail).body.to_s
# end
#
# def test_substitution_values
# to_email = "blah@exmaple.com"
# from_email = "wazzah@example.com"
# subject = "dis is a subject"
# body = "Ahhhnnnald has nahhhthiiing on dis body"
# mail = mail_factory(from_email, to_email,subject,body)
# assert_equal to_email , TMail::Mail.parse(mail).to.to_s
# assert_equal from_email, TMail::Mail.parse(mail).from.to_s
# assert_equal subject, TMail::Mail.parse(mail).subject.to_s
# assert_equal body+"\n", TMail::Mail.parse(mail).body.to_s
# end

## source ~/.bashrc
## export PS1='\[\033[0;32m\]\h\[\033[0;36m\] \w\[\033[00m\]: '
end
6 changes: 6 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
ENV['RAILS_ENV'] = 'test'
ENV['RAILS_ROOT'] ||= File.dirname(__FILE__) + '/../../../..'
require 'test/unit'
require File.expand_path(File.join(ENV['RAILS_ROOT'], 'config/environment.rb'))


1 change: 1 addition & 0 deletions uninstall.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Uninstall hook code here

0 comments on commit d11a34e

Please sign in to comment.