twmail 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -1
- data/README.md +2 -2
- data/bin/task-uuid +19 -3
- data/bin/twmail +17 -2
- data/bin/twmail-hook +37 -0
- data/doc/fetchmailrc.sample +4 -0
- data/lib/extensions/string.rb +6 -0
- data/lib/twmail/version.rb +1 -1
- data/lib/twmail.rb +2 -3
- data/test/unit/test_twmail_hooks +3 -3
- metadata +6 -4
- data/bin/twmail_hooks +0 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8f272ba50aeca1889982465e087e6c0a93d339a6
|
4
|
+
data.tar.gz: 9f9d78c93ae97f5cb17656c5d2e90f60672d72ac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 57bfec02d7f362c097b6d3c35d8214b8dcacd40ec2416d5b659b122c3ad495af5e709a1995abb9265b189aad46c683835a626583918dedaea15b1d17eedaa353
|
7
|
+
data.tar.gz: 75567e5613f8f112abbf11a9b97030fec4af4db5941e5b7a47cea691f857eaab0811afc61667ec4297e5c69c89603919dc47e377713df8780c94bdc28dd3fdd5
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -80,7 +80,7 @@ The approach chosen for `twmail` also addresses SPAM filtering. Handling that re
|
|
80
80
|
### Hooks
|
81
81
|
`twmail` comes with an advanced implementation that supports hooks. This makes handling incoming mail very simple for someone familiar with shell scripting, and there is no need to edit the `twmail` scripts in order to customize its behavior.
|
82
82
|
|
83
|
-
When `fetchmail` is configured to use `
|
83
|
+
When `fetchmail` is configured to use `twmail-hook` instead of `twmail`, the script will call the `twmail-hook` command (must be in the user's `$PATH`). Within the hook script, the fields of the parsed email are available as environment variables:
|
84
84
|
|
85
85
|
TWMAIL_DATE
|
86
86
|
TWMAIL_MESSAGE_ID
|
@@ -93,7 +93,7 @@ Have a look at test/helpers/test_hook for a very simple implementation.
|
|
93
93
|
|
94
94
|
If you prefer a hook with a different name, specify it in the `TWMAIL_HOOK` environment variable in your `.fetchmailrc`. For example, if your home directory contains a script called `taskwarrior-import.sh`, edit the `mda` line to look like this:
|
95
95
|
|
96
|
-
mda TWMAIL_HOOK=~/taskwarrior-import.sh
|
96
|
+
mda TWMAIL_HOOK=~/taskwarrior-import.sh twmail-hook
|
97
97
|
|
98
98
|
## Housekeeping
|
99
99
|
By default `fetchmail` will mark retrieved messages as read, but leave them on the server. For housekeeping purposes, it may be desirable to delete messages from the server once they were successfully imported into TaskWarrior.
|
data/bin/task-uuid
CHANGED
@@ -1,9 +1,25 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
require 'securerandom'
|
3
|
+
require 'optparse'
|
4
|
+
require 'twmail'
|
3
5
|
|
4
|
-
|
5
|
-
|
6
|
-
#
|
6
|
+
OptionParser.new do |opts|
|
7
|
+
banner = <<-HERE
|
8
|
+
#{opts.program_name} creates a new TaskWarrior task and prints its UUID to STDOUT using the following approach:
|
9
|
+
|
10
|
+
1. Make up a temporary tag name that is very unlikely to exist yet.
|
11
|
+
|
12
|
+
2. Create the new task tagged with our temporary tag
|
13
|
+
|
14
|
+
3. Use the name of our temporary tag to find the actual UUID generated by TaskWarrior
|
15
|
+
|
16
|
+
4. Remove the temporary tag from the new task
|
17
|
+
|
18
|
+
5. Print the UUID to STDOUT
|
19
|
+
HERE
|
20
|
+
opts.banner = banner#.wrap
|
21
|
+
opts.version = TaskWarriorMail::VERSION
|
22
|
+
end.parse!
|
7
23
|
|
8
24
|
# 1. Make a temporary tag that unlikely to exist yet.
|
9
25
|
# To avoid shell troubles, we have it start with a character.
|
data/bin/twmail
CHANGED
@@ -1,9 +1,24 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
require 'mail'
|
4
|
+
require 'optparse'
|
5
|
+
require 'twmail'
|
6
|
+
|
7
|
+
OptionParser.new do |opts|
|
8
|
+
banner = <<-HERE
|
9
|
+
#{opts.program_name} is a simple Mail Delivery Agent (MDA) that parses received mail and creates a new TaskWarrior task from the subject of the mail.
|
10
|
+
|
11
|
+
USAGE
|
12
|
+
|
13
|
+
Configure fetchmail to use #{opts.program_name} as MDA:
|
14
|
+
|
15
|
+
# ~/.fetchmailrc
|
16
|
+
mda #{opts.program_name}
|
17
|
+
HERE
|
18
|
+
opts.banner = banner#.wrap
|
19
|
+
opts.version = TaskWarriorMail::VERSION
|
20
|
+
end.parse!
|
4
21
|
|
5
|
-
# This script is a dead-simple Mail Delivery Agent (MDA) that parses the received email
|
6
|
-
# and creates a new TaskWarrior task from the subject of the mail.
|
7
22
|
mail = Mail.new(ARGF.read)
|
8
23
|
task_uuid = %x[task-uuid \"#{mail.subject}\"]
|
9
24
|
|
data/bin/twmail-hook
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'mail'
|
3
|
+
require 'optparse'
|
4
|
+
require 'twmail'
|
5
|
+
|
6
|
+
OptionParser.new do |opts|
|
7
|
+
banner = <<-HERE
|
8
|
+
#{opts.program_name} is a simple Mail Delivery Agent (MDA) that that exports the parts of the received email as environment variables and calls a shell script that can make use of these variables to further process the mail.
|
9
|
+
|
10
|
+
USAGE
|
11
|
+
|
12
|
+
Configure fetchmail to use #{opts.program_name} as MDA:
|
13
|
+
|
14
|
+
# ~/.fetchmailrc
|
15
|
+
mda #{opts.program_name}
|
16
|
+
|
17
|
+
HERE
|
18
|
+
opts.banner = banner#.wrap
|
19
|
+
opts.version = TaskWarriorMail::VERSION
|
20
|
+
end.parse!
|
21
|
+
|
22
|
+
mail = Mail.new(ARGF.read)
|
23
|
+
|
24
|
+
# Expose mail properties as environment variables
|
25
|
+
%w[date message_id from to subject body].each{|field|
|
26
|
+
value = mail.send(field.to_sym)
|
27
|
+
value = value.join(',') if value.respond_to?(:join)
|
28
|
+
ENV["TWMAIL_#{field.upcase}"] = Shellwords.escape(value.to_s)
|
29
|
+
}
|
30
|
+
|
31
|
+
# The hook to be executed is read from the environment variable TWMAIL_HOOK
|
32
|
+
# If none is set, this script will assume that twmail_on_new_mail is in the
|
33
|
+
# $PATH and executable.
|
34
|
+
cmd = ENV.fetch("TWMAIL_HOOK", 'twmail-hook')
|
35
|
+
|
36
|
+
# Call hook script
|
37
|
+
%x[#{cmd}]
|
data/lib/twmail/version.rb
CHANGED
data/lib/twmail.rb
CHANGED
data/test/unit/test_twmail_hooks
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/bin/bash
|
2
2
|
|
3
3
|
#
|
4
|
-
# Unit test for
|
4
|
+
# Unit test for twmail-hook
|
5
5
|
#
|
6
6
|
|
7
7
|
# Data locations
|
@@ -19,10 +19,10 @@ verbose=off
|
|
19
19
|
HERE
|
20
20
|
|
21
21
|
# Canonical path to test_hook
|
22
|
-
export
|
22
|
+
export twmail-hook=$DIRNAME/../helpers/test_hook
|
23
23
|
|
24
24
|
# Create new task using mail fixture
|
25
|
-
cat $DIRNAME/../fixtures/mail01.txt | $DIRNAME/../../bin/
|
25
|
+
cat $DIRNAME/../fixtures/mail01.txt | $DIRNAME/../../bin/twmail-hook
|
26
26
|
|
27
27
|
# Read back and run assertions
|
28
28
|
SUBJECT=$(task export | ruby -r json -e "puts JSON[ARGF.read].first['description']")
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: twmail
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nicholas E. Rabenau
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-11-
|
11
|
+
date: 2014-11-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: twtest
|
@@ -100,7 +100,7 @@ email:
|
|
100
100
|
executables:
|
101
101
|
- task-uuid
|
102
102
|
- twmail
|
103
|
-
-
|
103
|
+
- twmail-hook
|
104
104
|
extensions: []
|
105
105
|
extra_rdoc_files: []
|
106
106
|
files:
|
@@ -112,7 +112,9 @@ files:
|
|
112
112
|
- Rakefile
|
113
113
|
- bin/task-uuid
|
114
114
|
- bin/twmail
|
115
|
-
- bin/
|
115
|
+
- bin/twmail-hook
|
116
|
+
- doc/fetchmailrc.sample
|
117
|
+
- lib/extensions/string.rb
|
116
118
|
- lib/twmail.rb
|
117
119
|
- lib/twmail/version.rb
|
118
120
|
- test/fixtures/mail_empty.txt
|
data/bin/twmail_hooks
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
require 'mail'
|
3
|
-
|
4
|
-
# This script is a dead-simple Mail Delivery Agent (MDA) that exports the parts of the received email as
|
5
|
-
# environment variables and calls a shell script that can make use of these variables to further process
|
6
|
-
# the mail.
|
7
|
-
mail = Mail.new(ARGF.read)
|
8
|
-
|
9
|
-
# Expose mail properties as environment variables
|
10
|
-
%w[date message_id from to subject body].each{|field|
|
11
|
-
value = mail.send(field.to_sym)
|
12
|
-
value = value.join(',') if value.respond_to?(:join)
|
13
|
-
ENV["TWMAIL_#{field.upcase}"] = Shellwords.escape(value.to_s)
|
14
|
-
}
|
15
|
-
|
16
|
-
# The hook to be executed is read from the environment variable TWMAIL_HOOK
|
17
|
-
# If none is set, this script will assume that twmail_on_new_mail is in the
|
18
|
-
# $PATH and executable.
|
19
|
-
cmd = ENV["TWMAIL_HOOK"] || 'twmail_hook'
|
20
|
-
|
21
|
-
# Call hook script
|
22
|
-
%x[#{cmd}]
|