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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 182039b12dd834cc9fc05937002ef6072cd0c4c9
4
- data.tar.gz: eba7257ed83db3960f98ef42821372d278ae1cc7
3
+ metadata.gz: 8f272ba50aeca1889982465e087e6c0a93d339a6
4
+ data.tar.gz: 9f9d78c93ae97f5cb17656c5d2e90f60672d72ac
5
5
  SHA512:
6
- metadata.gz: 71199bf9f6e4759f6b236d7da0a48666510f9eefd3a5e391a327249cb1d4166dc511a29dcccdd5e0569d509ade886adfcdf19cf868421114126bf9dae5d9b8d1
7
- data.tar.gz: 327ff6c55daaa660f7364cf6c609e17ff5a84208ada8a938dde7870ec27bd726bb68d4524d3f85fb8014c4d40a644638b9e7558f0e6b7bffebc5eb5240ddb140
6
+ metadata.gz: 57bfec02d7f362c097b6d3c35d8214b8dcacd40ec2416d5b659b122c3ad495af5e709a1995abb9265b189aad46c683835a626583918dedaea15b1d17eedaa353
7
+ data.tar.gz: 75567e5613f8f112abbf11a9b97030fec4af4db5941e5b7a47cea691f857eaab0811afc61667ec4297e5c69c89603919dc47e377713df8780c94bdc28dd3fdd5
data/.gitignore CHANGED
@@ -7,7 +7,6 @@ Gemfile.lock
7
7
  InstalledFiles
8
8
  _yardoc
9
9
  coverage
10
- doc/
11
10
  lib/bundler/man
12
11
  pkg
13
12
  rdoc
@@ -15,3 +14,4 @@ spec/reports
15
14
  test/tmp
16
15
  test/version_tmp
17
16
  tmp
17
+ .cache_rake_t
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 `twmail_hooks` 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:
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 twmail_hooks
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
- # Creates a new task using TaskWarrior and prints its UUID to STDOUT.
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}]
@@ -0,0 +1,4 @@
1
+ poll "imap.gmail.com" proto imap port 993
2
+ user "tasks@example.com" password "passw0rd"
3
+ ssl
4
+ mda twmail
@@ -0,0 +1,6 @@
1
+ class String
2
+ # http://www.java2s.com/Code/Ruby/String/WordwrappingLinesofText.htm
3
+ def wrap(width = 78)
4
+ gsub(/(.{1,#{width}})(\s+|\Z)/, "\\1\n")
5
+ end
6
+ end
@@ -1,3 +1,3 @@
1
1
  module TaskWarriorMail
2
- VERSION = '0.0.4'
2
+ VERSION = '0.0.5'
3
3
  end
data/lib/twmail.rb CHANGED
@@ -1,6 +1,5 @@
1
- require 'mail'
2
-
3
- require "twmail/version"
1
+ require 'twmail/version'
2
+ require 'extensions/string'
4
3
 
5
4
  module TaskWarriorMail
6
5
  # Your code goes here...
@@ -1,7 +1,7 @@
1
1
  #!/bin/bash
2
2
 
3
3
  #
4
- # Unit test for twmail_hooks
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 TWMAIL_HOOK=$DIRNAME/../helpers/test_hook
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/twmail_hooks
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
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-15 00:00:00.000000000 Z
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
- - twmail_hooks
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/twmail_hooks
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}]