tmail_metas 0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +35 -0
- data/lib/tmail_metas.rb +22 -0
- metadata +56 -0
data/README.rdoc
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
=TMail Meta Data Functionality
|
2
|
+
|
3
|
+
Allows you to include extra data within the body of e-mail messages for use in automated parsing through TMail.
|
4
|
+
|
5
|
+
=Settings
|
6
|
+
|
7
|
+
If you need to override the default scanner you can run this:
|
8
|
+
|
9
|
+
TMail::Metas.scanner = /Metas\((.*)\)/
|
10
|
+
TMail::Metas.scanner_options = {:seperator => ':', :group_seperator => ','}
|
11
|
+
|
12
|
+
# which will look for this:
|
13
|
+
# Metas(project_id:12,type:message)
|
14
|
+
|
15
|
+
=Example
|
16
|
+
|
17
|
+
%w{pp rubygems tmail tmail_metas}.each { |lib| require lib }
|
18
|
+
|
19
|
+
EMAIL = <<-end
|
20
|
+
To: you@example.com
|
21
|
+
From: me@example.com
|
22
|
+
Subject: This is my automated email
|
23
|
+
|
24
|
+
This is an email which will be automatically handled by a ruby script!
|
25
|
+
The body will be stripped of these meta tags while they are made available
|
26
|
+
in the mail.metas hash.
|
27
|
+
|
28
|
+
{{project_id=12345&category=Incoming Emails&create=message}}
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
mail = TMail::Mail.parse(EMAIL)
|
33
|
+
|
34
|
+
pp mail.metas # => {"category"=>"Incoming Emails", "project_id"=>"12345", "create"=>"message"}
|
35
|
+
pp mail.body # => (body with the {{...}} metas stripped)
|
data/lib/tmail_metas.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
module TMail
|
2
|
+
module Metas
|
3
|
+
# Looks for {{key=value[&something=value]}} pairs within the mail's body by default
|
4
|
+
@@meta_tag_scanner = /\s*\{\{\s*(.*)\s*\}\}\s*/m
|
5
|
+
# group_seperator:: what break each key,value pair
|
6
|
+
# seperator:: what breaks keys and values apart
|
7
|
+
@@meta_scanner_options = {
|
8
|
+
:group_seperator => '&',
|
9
|
+
:seperator => '='
|
10
|
+
}
|
11
|
+
def self.scanner=(scanner); @@meta_tag_scanner = scanner end
|
12
|
+
def self.scanner_options=(options); @@meta_scanner_options = options end
|
13
|
+
def metas
|
14
|
+
@metas ||= Hash[*$1.split(@@meta_scanner_options[:group_seperator]).map do |group|
|
15
|
+
group.split(@@meta_scanner_options[:seperator]).map(&:strip)
|
16
|
+
end.flatten] if body =~ @@meta_tag_scanner
|
17
|
+
self.body = body.gsub(@@meta_tag_scanner, '')
|
18
|
+
@metas
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
TMail::Mail.send(:include, TMail::Metas)
|
metadata
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tmail_metas
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: "0.1"
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Rob Hurring
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-10-15 00:00:00 -04:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description:
|
17
|
+
email: rob@zerobased.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files: []
|
23
|
+
|
24
|
+
files:
|
25
|
+
- README.rdoc
|
26
|
+
- lib/tmail_metas.rb
|
27
|
+
has_rdoc: true
|
28
|
+
homepage: http://github.com/robhurring/tmail-metas
|
29
|
+
licenses: []
|
30
|
+
|
31
|
+
post_install_message:
|
32
|
+
rdoc_options: []
|
33
|
+
|
34
|
+
require_paths:
|
35
|
+
- lib
|
36
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: "0"
|
41
|
+
version:
|
42
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: "0"
|
47
|
+
version:
|
48
|
+
requirements: []
|
49
|
+
|
50
|
+
rubyforge_project:
|
51
|
+
rubygems_version: 1.3.5
|
52
|
+
signing_key:
|
53
|
+
specification_version: 3
|
54
|
+
summary: Enables extra meta data options for TMail::Mail objects
|
55
|
+
test_files: []
|
56
|
+
|