pastehub 0.4.2 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/Rakefile +4 -1
- data/VERSION.yml +2 -2
- data/bin/PastehubSync +0 -33
- data/lib/pastehub.rb +1 -0
- data/lib/pastehub/client.rb +7 -0
- data/lib/pastehub/clientsync.rb +4 -7
- data/lib/pastehub/config.rb +11 -2
- data/lib/pastehub/plugin.rb +70 -0
- data/lib/pastehub/plugin/dropbox_todo.rb +64 -0
- data/lib/pastehub/plugin/notification_center.rb +73 -0
- data/lib/pastehub/plugin/sample.rb +43 -0
- data/lib/pastehub/plugin/sendmail.rb +121 -0
- data/lib/pastehub/plugin_base.rb +43 -0
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a01fa2d11546477436fdcfabfb078611ad6703fc
|
4
|
+
data.tar.gz: cd4b9982587c99b62620af701df08c58a55675c7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a77838b34dd3d3ca9cfdb918ad7d2c2af2255a339464849e27b0890e84fac26d71e5e6cd041c9e7a56cee1a9baf62a090c2bf86830c80b042d1eddeac24a4cce
|
7
|
+
data.tar.gz: 46195274032f1740d99003045051b8a19d359be9a8d1e46cf2fb9b1f969a11120c94a391ca72ea7413f02948c80afa71c4eae8cc2772b6b20f66e9164848fd68
|
data/README.md
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
PasteHub
|
2
2
|
=======================
|
3
3
|
|
4
|
-
|
5
4
|
## Concept
|
6
5
|
|
7
6
|
Cross-platform clipboard (copy and paste) sync tool.
|
@@ -20,6 +19,7 @@ Linux(gem) | not yet | OK | OK |
|
|
20
19
|
|
21
20
|
+ [Dropbox](./doc/client/dropbox.md)
|
22
21
|
+ [RubyGems](./doc/client/ruby_gems.md)
|
22
|
+
+ [Plugins](./doc/client/plugins.md)
|
23
23
|
+ [Setup Emacs](./doc/client/setup_emacs.md)
|
24
24
|
+ [Setup Vim](./doc/client/setup_vim.md)
|
25
25
|
|
data/Rakefile
CHANGED
@@ -26,7 +26,7 @@ begin
|
|
26
26
|
'README.txt',
|
27
27
|
'bin/*',
|
28
28
|
'lib/*.rb',
|
29
|
-
'lib
|
29
|
+
'lib/**/*.rb',
|
30
30
|
].to_a
|
31
31
|
# gemspec.add_dependency( "json", "1.8.1")
|
32
32
|
gemspec.add_dependency( "clipboard", "1.0.5" )
|
@@ -50,6 +50,9 @@ task :test do
|
|
50
50
|
sh "ruby -I ./lib `which rspec` -b ./test/libsyncentry_spec.rb "
|
51
51
|
sh "ruby -I ./lib `which rspec` -b ./test/libutil_spec.rb "
|
52
52
|
sh "ruby -I ./lib `which rspec` -b ./test/libclipboard_spec.rb "
|
53
|
+
sh "ruby -I ./lib `which rspec` -b ./test/libplugin_spec.rb "
|
54
|
+
sh "ruby -I ./lib `which rspec` -b ./test/plugin_dropbox_todo_spec.rb "
|
55
|
+
sh "ruby -I ./lib `which rspec` -b ./test/plugin_sendmail_spec.rb "
|
53
56
|
end
|
54
57
|
|
55
58
|
task :sync do
|
data/VERSION.yml
CHANGED
data/bin/PastehubSync
CHANGED
@@ -76,39 +76,6 @@ def main( argv )
|
|
76
76
|
|
77
77
|
# create clientSync
|
78
78
|
clientSync = PasteHub::ClientSync.new( hostname, 1.0 )
|
79
|
-
|
80
|
-
# add notification handler
|
81
|
-
receiveNotifyFunc =
|
82
|
-
case RbConfig::CONFIG['host_os']
|
83
|
-
when /^darwin/
|
84
|
-
# MacOS X
|
85
|
-
notifier_path = RbConfig::CONFIG['bindir'] + "/" + "terminal-notifier"
|
86
|
-
if File.exist?( notifier_path )
|
87
|
-
STDERR.puts( "Info: found terminal-notifier for MacOS X." )
|
88
|
-
lambda { |x|
|
89
|
-
str = if config.notifyMessageMax < x.size
|
90
|
-
x[0...config.notifyMessageMax] + " ..."
|
91
|
-
else
|
92
|
-
x
|
93
|
-
end
|
94
|
-
url_option = ''
|
95
|
-
util = PasteHub::Util.new
|
96
|
-
if util.pulloutURL( str )
|
97
|
-
url_option = '-open \'' + util.pulloutURL( str ) + '\''
|
98
|
-
end
|
99
|
-
command = sprintf( "%s -title 'PasteHub' -message '\\%s' %s", notifier_path, str, url_option )
|
100
|
-
system( command )
|
101
|
-
}
|
102
|
-
else
|
103
|
-
nil
|
104
|
-
end
|
105
|
-
else
|
106
|
-
lambda { |x|
|
107
|
-
# nothing to do.
|
108
|
-
}
|
109
|
-
end
|
110
|
-
|
111
|
-
clientSync.addNoitfyCallback( receiveNotifyFunc )
|
112
79
|
|
113
80
|
while true
|
114
81
|
signals = 0
|
data/lib/pastehub.rb
CHANGED
data/lib/pastehub/client.rb
CHANGED
@@ -45,6 +45,7 @@ module PasteHub
|
|
45
45
|
def self.setupDirectory
|
46
46
|
localdb_path = PasteHub::Config.instance.localDbPath
|
47
47
|
localsync_path = PasteHub::Config.instance.localSyncPath
|
48
|
+
public_path = PasteHub::Config.instance.publicPath
|
48
49
|
# Create directory
|
49
50
|
if not File.exist?( localdb_path )
|
50
51
|
FileUtils.mkdir_p( localdb_path, { :mode => 0700 } )
|
@@ -54,6 +55,12 @@ module PasteHub
|
|
54
55
|
if not File.exist?( localsync_path )
|
55
56
|
FileUtils.mkdir_p( localsync_path, { :mode => 0700 } )
|
56
57
|
end
|
58
|
+
|
59
|
+
# Create Dropbox/Public directory
|
60
|
+
if not File.exist?( public_path )
|
61
|
+
FileUtils.mkdir_p( public_path, { :mode => 0700 } )
|
62
|
+
end
|
63
|
+
|
57
64
|
return true
|
58
65
|
end
|
59
66
|
|
data/lib/pastehub/clientsync.rb
CHANGED
@@ -113,15 +113,12 @@ module PasteHub
|
|
113
113
|
@polling_interval = polling_interval
|
114
114
|
@status = Status.new()
|
115
115
|
@last_modify_time = Time.now()
|
116
|
-
|
117
|
-
|
118
|
-
def addNoitfyCallback( receiveNotifyFunc )
|
119
|
-
@receiveNotifyFunc = receiveNotifyFunc
|
116
|
+
@plugin = PasteHub::Plugin
|
117
|
+
@plugin.load_plugins
|
120
118
|
end
|
121
119
|
|
122
|
-
def notifyToReceive(
|
123
|
-
@
|
124
|
-
@status.inc( )
|
120
|
+
def notifyToReceive(message)
|
121
|
+
@plugin.distribute_newly_arrived(message)
|
125
122
|
end
|
126
123
|
|
127
124
|
# host's sync data file excludes local hostname
|
data/lib/pastehub/config.rb
CHANGED
@@ -45,7 +45,11 @@ module PasteHub
|
|
45
45
|
def initialize( )
|
46
46
|
self.setupClient( {} )
|
47
47
|
@verbose_flag = false
|
48
|
-
@notifyMessageMax =
|
48
|
+
@notifyMessageMax = 100
|
49
|
+
end
|
50
|
+
|
51
|
+
def reinitialize()
|
52
|
+
initialize()
|
49
53
|
end
|
50
54
|
|
51
55
|
def getHomeDirectory( )
|
@@ -76,6 +80,11 @@ module PasteHub
|
|
76
80
|
else
|
77
81
|
File.expand_path( sprintf( "%s/Dropbox/pastehub/", getHomeDirectory() )) + "/"
|
78
82
|
end
|
83
|
+
@publicPath = if hash[ :publicPath ]
|
84
|
+
hash[ :publicPath ]
|
85
|
+
else
|
86
|
+
File.expand_path( sprintf( "%s/Dropbox/Public/", getHomeDirectory() )) + "/"
|
87
|
+
end
|
79
88
|
end
|
80
89
|
|
81
90
|
def loadClient()
|
@@ -90,6 +99,6 @@ module PasteHub
|
|
90
99
|
end
|
91
100
|
end
|
92
101
|
|
93
|
-
attr_reader :localDbPath, :localSyncPath, :notifyMessageMax
|
102
|
+
attr_reader :localDbPath, :localSyncPath, :publicPath, :notifyMessageMax
|
94
103
|
end
|
95
104
|
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
#
|
2
|
+
# plugin.rb - PasteHub's plugin loader
|
3
|
+
#
|
4
|
+
# Copyright (c) 2014-2014 Kiyoka Nishiyama <kiyoka@sumibi.org>
|
5
|
+
#
|
6
|
+
# Redistribution and use in source and binary forms, with or without
|
7
|
+
# modification, are permitted provided that the following conditions
|
8
|
+
# are met:
|
9
|
+
#
|
10
|
+
# 1. Redistributions of source code must retain the above copyright
|
11
|
+
# notice, this list of conditions and the following disclaimer.
|
12
|
+
#
|
13
|
+
# 2. Redistributions in binary form must reproduce the above copyright
|
14
|
+
# notice, this list of conditions and the following disclaimer in the
|
15
|
+
# documentation and/or other materials provided with the distribution.
|
16
|
+
#
|
17
|
+
# 3. Neither the name of the authors nor the names of its contributors
|
18
|
+
# may be used to endorse or promote products derived from this
|
19
|
+
# software without specific prior written permission.
|
20
|
+
#
|
21
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
22
|
+
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
23
|
+
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
24
|
+
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
25
|
+
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
26
|
+
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
27
|
+
# TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
28
|
+
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
29
|
+
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
30
|
+
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
31
|
+
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
32
|
+
#
|
33
|
+
#
|
34
|
+
module PasteHub
|
35
|
+
class PluginClass
|
36
|
+
attr_reader :plugins
|
37
|
+
|
38
|
+
def initialize
|
39
|
+
@plugins = []
|
40
|
+
end
|
41
|
+
|
42
|
+
def load_plugins
|
43
|
+
dir = File.join(File.dirname(__FILE__), "plugin")
|
44
|
+
load_plugin_dir(dir)
|
45
|
+
end
|
46
|
+
|
47
|
+
def load_plugin_dir(dir)
|
48
|
+
dir = File.expand_path(dir)
|
49
|
+
Dir.entries(dir).sort.each {|filename|
|
50
|
+
if filename =~ /\.rb$/
|
51
|
+
require File.join(dir, filename)
|
52
|
+
end
|
53
|
+
}
|
54
|
+
nil
|
55
|
+
end
|
56
|
+
|
57
|
+
def register_plugin(obj)
|
58
|
+
#STDERR.printf( "Info: plugin [%s] loaded.\n", obj.class.to_s )
|
59
|
+
@plugins << obj
|
60
|
+
end
|
61
|
+
|
62
|
+
def distribute_newly_arrived(message)
|
63
|
+
@plugins.each { |obj|
|
64
|
+
obj.newly_arrived(message)
|
65
|
+
}
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
Plugin = PluginClass.new
|
70
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
#
|
2
|
+
# dropbox_todo.rb - Plugin: Add todo as dropbox file.
|
3
|
+
#
|
4
|
+
# Copyright (c) 2014-2014 Kiyoka Nishiyama <kiyoka@sumibi.org>
|
5
|
+
#
|
6
|
+
# Redistribution and use in source and binary forms, with or without
|
7
|
+
# modification, are permitted provided that the following conditions
|
8
|
+
# are met:
|
9
|
+
#
|
10
|
+
# 1. Redistributions of source code must retain the above copyright
|
11
|
+
# notice, this list of conditions and the following disclaimer.
|
12
|
+
#
|
13
|
+
# 2. Redistributions in binary form must reproduce the above copyright
|
14
|
+
# notice, this list of conditions and the following disclaimer in the
|
15
|
+
# documentation and/or other materials provided with the distribution.
|
16
|
+
#
|
17
|
+
# 3. Neither the name of the authors nor the names of its contributors
|
18
|
+
# may be used to endorse or promote products derived from this
|
19
|
+
# software without specific prior written permission.
|
20
|
+
#
|
21
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
22
|
+
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
23
|
+
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
24
|
+
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
25
|
+
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
26
|
+
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
27
|
+
# TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
28
|
+
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
29
|
+
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
30
|
+
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
31
|
+
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
32
|
+
#
|
33
|
+
#
|
34
|
+
require 'pastehub/plugin_base'
|
35
|
+
|
36
|
+
module PasteHub
|
37
|
+
class DropboxTodo < PluginBase
|
38
|
+
|
39
|
+
def todo?(message)
|
40
|
+
m = message.match( /(^|[ ])[#]todo([ ]|$)/i )
|
41
|
+
if m
|
42
|
+
message.gsub( /[ ]?[#]todo[ ]?/i, "" )
|
43
|
+
else
|
44
|
+
nil
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def newly_arrived(message)
|
49
|
+
config = PasteHub::Config.instance
|
50
|
+
path = config.publicPath
|
51
|
+
filename = todo?(message)
|
52
|
+
if filename
|
53
|
+
FileUtils.mkdir_p( path + "pastehub_todo/", { :mode => 0700 } )
|
54
|
+
open( path + "pastehub_todo/" + filename + ".txt", "w" ) {|f|
|
55
|
+
f.puts "pastehub todo"
|
56
|
+
}
|
57
|
+
STDERR.printf( "Info: Added todo [%s]\n", filename )
|
58
|
+
end
|
59
|
+
nil
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
Plugin.register_plugin(DropboxTodo.new)
|
64
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
#
|
2
|
+
# notification_center.rb - NotificationCenter plugin for MacOS X
|
3
|
+
#
|
4
|
+
# Copyright (c) 2014-2014 Kiyoka Nishiyama <kiyoka@sumibi.org>
|
5
|
+
#
|
6
|
+
# Redistribution and use in source and binary forms, with or without
|
7
|
+
# modification, are permitted provided that the following conditions
|
8
|
+
# are met:
|
9
|
+
#
|
10
|
+
# 1. Redistributions of source code must retain the above copyright
|
11
|
+
# notice, this list of conditions and the following disclaimer.
|
12
|
+
#
|
13
|
+
# 2. Redistributions in binary form must reproduce the above copyright
|
14
|
+
# notice, this list of conditions and the following disclaimer in the
|
15
|
+
# documentation and/or other materials provided with the distribution.
|
16
|
+
#
|
17
|
+
# 3. Neither the name of the authors nor the names of its contributors
|
18
|
+
# may be used to endorse or promote products derived from this
|
19
|
+
# software without specific prior written permission.
|
20
|
+
#
|
21
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
22
|
+
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
23
|
+
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
24
|
+
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
25
|
+
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
26
|
+
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
27
|
+
# TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
28
|
+
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
29
|
+
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
30
|
+
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
31
|
+
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
32
|
+
#
|
33
|
+
#
|
34
|
+
require 'pastehub/plugin_base'
|
35
|
+
|
36
|
+
module PasteHub
|
37
|
+
class NotificationCenter < PluginBase
|
38
|
+
|
39
|
+
def initialize()
|
40
|
+
@enable = false
|
41
|
+
case RbConfig::CONFIG['host_os']
|
42
|
+
when /^darwin/
|
43
|
+
# MacOS X
|
44
|
+
@notifier_path = RbConfig::CONFIG['bindir'] + "/" + "terminal-notifier"
|
45
|
+
if File.exist?( @notifier_path )
|
46
|
+
STDERR.puts( "Info: found terminal-notifier for MacOS X." )
|
47
|
+
@enable = true
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def newly_arrived(message)
|
53
|
+
config = PasteHub::Config.instance
|
54
|
+
if @enable
|
55
|
+
str = if config.notifyMessageMax < message.size
|
56
|
+
message[0...config.notifyMessageMax] + " ..."
|
57
|
+
else
|
58
|
+
message
|
59
|
+
end
|
60
|
+
url_option = ''
|
61
|
+
util = PasteHub::Util.new
|
62
|
+
if util.pulloutURL( str )
|
63
|
+
url_option = '-open \'' + util.pulloutURL( str ) + '\''
|
64
|
+
end
|
65
|
+
command = sprintf( "%s -title 'PasteHub' -message '\\%s' %s", @notifier_path, str, url_option )
|
66
|
+
system( command )
|
67
|
+
end
|
68
|
+
nil
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
Plugin.register_plugin(NotificationCenter.new)
|
73
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
#
|
2
|
+
# sample.rb - a PasteHub's plugin sample ( nothing to do )
|
3
|
+
#
|
4
|
+
# Copyright (c) 2014-2014 Kiyoka Nishiyama <kiyoka@sumibi.org>
|
5
|
+
#
|
6
|
+
# Redistribution and use in source and binary forms, with or without
|
7
|
+
# modification, are permitted provided that the following conditions
|
8
|
+
# are met:
|
9
|
+
#
|
10
|
+
# 1. Redistributions of source code must retain the above copyright
|
11
|
+
# notice, this list of conditions and the following disclaimer.
|
12
|
+
#
|
13
|
+
# 2. Redistributions in binary form must reproduce the above copyright
|
14
|
+
# notice, this list of conditions and the following disclaimer in the
|
15
|
+
# documentation and/or other materials provided with the distribution.
|
16
|
+
#
|
17
|
+
# 3. Neither the name of the authors nor the names of its contributors
|
18
|
+
# may be used to endorse or promote products derived from this
|
19
|
+
# software without specific prior written permission.
|
20
|
+
#
|
21
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
22
|
+
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
23
|
+
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
24
|
+
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
25
|
+
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
26
|
+
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
27
|
+
# TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
28
|
+
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
29
|
+
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
30
|
+
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
31
|
+
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
32
|
+
#
|
33
|
+
#
|
34
|
+
require 'pastehub/plugin_base'
|
35
|
+
module PasteHub
|
36
|
+
class PluginSample < PluginBase
|
37
|
+
def newly_arrived(message)
|
38
|
+
# STDERR.puts "PluginSample: message arrived [#{message}]"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
Plugin.register_plugin(PluginSample.new)
|
43
|
+
end
|
@@ -0,0 +1,121 @@
|
|
1
|
+
#
|
2
|
+
# sendmail.rb - Plugin: send clipboard message by e-mail.
|
3
|
+
#
|
4
|
+
# Copyright (c) 2014-2014 Kiyoka Nishiyama <kiyoka@sumibi.org>
|
5
|
+
#
|
6
|
+
# Redistribution and use in source and binary forms, with or without
|
7
|
+
# modification, are permitted provided that the following conditions
|
8
|
+
# are met:
|
9
|
+
#
|
10
|
+
# 1. Redistributions of source code must retain the above copyright
|
11
|
+
# notice, this list of conditions and the following disclaimer.
|
12
|
+
#
|
13
|
+
# 2. Redistributions in binary form must reproduce the above copyright
|
14
|
+
# notice, this list of conditions and the following disclaimer in the
|
15
|
+
# documentation and/or other materials provided with the distribution.
|
16
|
+
#
|
17
|
+
# 3. Neither the name of the authors nor the names of its contributors
|
18
|
+
# may be used to endorse or promote products derived from this
|
19
|
+
# software without specific prior written permission.
|
20
|
+
#
|
21
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
22
|
+
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
23
|
+
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
24
|
+
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
25
|
+
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
26
|
+
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
27
|
+
# TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
28
|
+
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
29
|
+
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
30
|
+
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
31
|
+
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
32
|
+
#
|
33
|
+
#
|
34
|
+
require 'pastehub/plugin_base'
|
35
|
+
|
36
|
+
module PasteHub
|
37
|
+
class MailSetting
|
38
|
+
attr_accessor :tag
|
39
|
+
attr_accessor :mail
|
40
|
+
|
41
|
+
def to_s()
|
42
|
+
return @tag + "," + @mail
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
class SendMail < PluginBase
|
47
|
+
attr_reader :mail_settings
|
48
|
+
attr_accessor :mail_command
|
49
|
+
|
50
|
+
def initialize()
|
51
|
+
@mail_command = "mail"
|
52
|
+
# load env variables
|
53
|
+
@mail_settings = 10.times.collect {|n|
|
54
|
+
mail_setting = MailSetting.new
|
55
|
+
val = ENV[ sprintf("PASTEHUB_MAIL%d", n) ]
|
56
|
+
if val
|
57
|
+
if val.match(/^[a-zA-Z]+[,][a-zA-Z0-9_.-]+[@].+$/)
|
58
|
+
arr = val.split(/,/)
|
59
|
+
mail_setting.tag = arr[0]
|
60
|
+
mail_setting.mail = arr[1]
|
61
|
+
mail_setting
|
62
|
+
else
|
63
|
+
nil
|
64
|
+
end
|
65
|
+
else
|
66
|
+
nil
|
67
|
+
end
|
68
|
+
}.select( ) {|x| x}
|
69
|
+
# display settings
|
70
|
+
@mail_settings.each { |setting|
|
71
|
+
STDERR.printf( "Info: SendMail-plugin tag:[%s] mail[%s]\n",
|
72
|
+
setting.tag,
|
73
|
+
setting.mail )
|
74
|
+
}
|
75
|
+
end
|
76
|
+
|
77
|
+
def sendmail?(message)
|
78
|
+
arr = mail_settings.collect { |setting|
|
79
|
+
tag_exp = sprintf("(^|[ ])[#]%s([ ]|$)", setting.tag)
|
80
|
+
regexp = Regexp.new(tag_exp)
|
81
|
+
if regexp.match(message)
|
82
|
+
setting.mail
|
83
|
+
else
|
84
|
+
nil
|
85
|
+
end
|
86
|
+
}.select( ) {|x| x}
|
87
|
+
if 0 < arr.size
|
88
|
+
arr[0]
|
89
|
+
else
|
90
|
+
nil
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def encode_subject(subject)
|
95
|
+
enc_str = Base64.strict_encode64(subject)
|
96
|
+
"=?utf-8?B?" + enc_str + "?="
|
97
|
+
end
|
98
|
+
|
99
|
+
def newly_arrived(message)
|
100
|
+
mailaddress = sendmail?(message)
|
101
|
+
lines = message.split( /\n/ )
|
102
|
+
if mailaddress
|
103
|
+
command = sprintf( "|%s %s -i -s '%s'", @mail_command, mailaddress, encode_subject(lines[0]))
|
104
|
+
if @mail_command
|
105
|
+
p @mail_command
|
106
|
+
open( command, "w" ) {|f|
|
107
|
+
f.print message
|
108
|
+
}
|
109
|
+
STDERR.printf( "Info: send mail [%s]\n", command )
|
110
|
+
nil
|
111
|
+
else
|
112
|
+
command
|
113
|
+
end
|
114
|
+
else
|
115
|
+
nil
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
Plugin.register_plugin(SendMail.new)
|
121
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
#
|
2
|
+
# plugin_base.rb - Base class for plugin implementation.
|
3
|
+
#
|
4
|
+
# Copyright (c) 2014-2014 Kiyoka Nishiyama <kiyoka@sumibi.org>
|
5
|
+
#
|
6
|
+
# Redistribution and use in source and binary forms, with or without
|
7
|
+
# modification, are permitted provided that the following conditions
|
8
|
+
# are met:
|
9
|
+
#
|
10
|
+
# 1. Redistributions of source code must retain the above copyright
|
11
|
+
# notice, this list of conditions and the following disclaimer.
|
12
|
+
#
|
13
|
+
# 2. Redistributions in binary form must reproduce the above copyright
|
14
|
+
# notice, this list of conditions and the following disclaimer in the
|
15
|
+
# documentation and/or other materials provided with the distribution.
|
16
|
+
#
|
17
|
+
# 3. Neither the name of the authors nor the names of its contributors
|
18
|
+
# may be used to endorse or promote products derived from this
|
19
|
+
# software without specific prior written permission.
|
20
|
+
#
|
21
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
22
|
+
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
23
|
+
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
24
|
+
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
25
|
+
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
26
|
+
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
27
|
+
# TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
28
|
+
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
29
|
+
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
30
|
+
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
31
|
+
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
32
|
+
#
|
33
|
+
#
|
34
|
+
module PasteHub
|
35
|
+
class PluginBase
|
36
|
+
def initialize
|
37
|
+
end
|
38
|
+
|
39
|
+
# for customization of newly arraived message.
|
40
|
+
def newly_arrived (message)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pastehub
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kiyoka Nishiyama
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-03-
|
11
|
+
date: 2014-03-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: clipboard
|
@@ -156,6 +156,12 @@ files:
|
|
156
156
|
- lib/pastehub/clientsync.rb
|
157
157
|
- lib/pastehub/clipboard.rb
|
158
158
|
- lib/pastehub/config.rb
|
159
|
+
- lib/pastehub/plugin.rb
|
160
|
+
- lib/pastehub/plugin/dropbox_todo.rb
|
161
|
+
- lib/pastehub/plugin/notification_center.rb
|
162
|
+
- lib/pastehub/plugin/sample.rb
|
163
|
+
- lib/pastehub/plugin/sendmail.rb
|
164
|
+
- lib/pastehub/plugin_base.rb
|
159
165
|
- lib/pastehub/syncentry.rb
|
160
166
|
- lib/pastehub/util.rb
|
161
167
|
- README.md
|