hail.rb 2015.10.11.20.41
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 +7 -0
- data/bin/hail +4 -0
- data/lib/hail/account.rb +35 -0
- data/lib/hail/accounts.rb +14 -0
- data/lib/hail/gui.rb +97 -0
- data/lib/hail/mail.rb +14 -0
- data/lib/hail.rb +18 -0
- metadata +50 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 00e972e037991b6d9657fe533f509be688a0bfda
|
4
|
+
data.tar.gz: 852c08fa7becff0b4106fe65631228eef0c9e318
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0cacdfd50a685ac0d53566264b01cd03ba2d98da2c03320f2842510f239097352bd5a07fac1d1ced002a2d77341629cd004a4629f92ac360a9e1cc691dc4b46f
|
7
|
+
data.tar.gz: 6296f602edb6a4ac98c43ac1146cc34c8bef4e050b4e469c64742e7ca76c5282e7bb7b1a28e40e9560cdfdccd3f49c17efa79965c91336396bf908f70de3e681
|
data/bin/hail
ADDED
data/lib/hail/account.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'date'
|
2
|
+
require 'base64'
|
3
|
+
|
4
|
+
class Hail::Account
|
5
|
+
def initialize(config)
|
6
|
+
@config = config
|
7
|
+
end
|
8
|
+
|
9
|
+
def connect
|
10
|
+
@imap = Net::IMAP.new(@config[:address], @config[:port], @config[:tls])
|
11
|
+
@imap.authenticate('LOGIN', @config[:user], @config[:password])
|
12
|
+
|
13
|
+
@imap.select('INBOX')
|
14
|
+
list =[]
|
15
|
+
|
16
|
+
|
17
|
+
list = {name: [], subject: [], date: []}
|
18
|
+
@imap.sort(["REVERSE", "SUBJECT"], ["ALL"], "US-ASCII").each do |message_id|
|
19
|
+
envelope = @imap.fetch(message_id, "ENVELOPE")[0].attr["ENVELOPE"]
|
20
|
+
list[:name] << Hail::Mail.header_readable(envelope.from[0].name)
|
21
|
+
list[:subject] << Hail::Mail.header_readable(envelope.subject)
|
22
|
+
|
23
|
+
date = @imap.fetch(message_id, "INTERNALDATE")[0].attr["INTERNALDATE"]
|
24
|
+
date = DateTime.parse(date)
|
25
|
+
if Date.today === date
|
26
|
+
date = date.strftime("%H:%M")
|
27
|
+
else
|
28
|
+
date = date.strftime("%d/%m/%Y %H:%M")
|
29
|
+
end
|
30
|
+
list[:date] << date.to_s
|
31
|
+
end
|
32
|
+
|
33
|
+
Hail::GUI.instance.buffer! list
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class Hail::Accounts < Hash
|
2
|
+
def initialize()
|
3
|
+
super
|
4
|
+
file = YAML.load_file(Dir.home + "/.config/hail/account.yaml")
|
5
|
+
file.each do |account, account_config|
|
6
|
+
self[account] = Hail::Account.new(account_config)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def []=(key, value)
|
11
|
+
value.connect
|
12
|
+
super
|
13
|
+
end
|
14
|
+
end
|
data/lib/hail/gui.rb
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
require 'singleton'
|
2
|
+
|
3
|
+
class Hail::GUI
|
4
|
+
include Singleton
|
5
|
+
|
6
|
+
def initialize()
|
7
|
+
@buffer = []
|
8
|
+
@render_buffer = 0
|
9
|
+
Curses.init_screen()
|
10
|
+
end
|
11
|
+
|
12
|
+
def win
|
13
|
+
@win
|
14
|
+
end
|
15
|
+
|
16
|
+
def render
|
17
|
+
@win = Curses::Window.new(0, 0, 0, 0)
|
18
|
+
area = {height: win.maxy, width: win.maxx, top: 0, left: 0}
|
19
|
+
|
20
|
+
win.clear
|
21
|
+
@buffer[@render_buffer].to_hg(area) if not @buffer[@render_buffer].nil?
|
22
|
+
win.refresh
|
23
|
+
win.getch
|
24
|
+
end
|
25
|
+
|
26
|
+
def buffer=(buffer)
|
27
|
+
@render_buffer = buffer
|
28
|
+
end
|
29
|
+
|
30
|
+
def buffer!(buffer)
|
31
|
+
@buffer.insert(-1, buffer)
|
32
|
+
@buffer[-1]
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
class Hash
|
37
|
+
def to_hg(area)
|
38
|
+
width = area[:width] / self.length
|
39
|
+
i = 0
|
40
|
+
self.each do |k,v|
|
41
|
+
header = [k.to_s, "-" * (width - 5)]
|
42
|
+
subarea = {height: area[:height], width: i+1*width, top: area[:top], left: area[:left]+(i*width)}
|
43
|
+
header.to_hg(subarea)
|
44
|
+
|
45
|
+
#List
|
46
|
+
subarea = {height: area[:height] - header.__hg_height, width: i+1*width, top: area[:top] + header.__hg_height, left: area[:left]+(i*width)}
|
47
|
+
v.to_hg(subarea)
|
48
|
+
i += 1
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
class Array
|
54
|
+
def __hg_height
|
55
|
+
height = 0
|
56
|
+
self.each do |v|
|
57
|
+
height += v.__hg_height
|
58
|
+
end
|
59
|
+
height
|
60
|
+
end
|
61
|
+
|
62
|
+
def to_hg(area)
|
63
|
+
top = area[:top]
|
64
|
+
self.each do |v|
|
65
|
+
subarea = {height: area[:top]-top, width: area[:width], top: top, left: area[:left]}
|
66
|
+
if not v.nil?
|
67
|
+
v.to_hg(subarea)
|
68
|
+
top = top + v.__hg_height
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
class String
|
75
|
+
def __hg_height
|
76
|
+
1
|
77
|
+
end
|
78
|
+
|
79
|
+
def __truncate(truncate_at, options = {})
|
80
|
+
return dup unless length > truncate_at
|
81
|
+
|
82
|
+
omission = options[:omission] || '...'
|
83
|
+
length_with_room_for_omission = truncate_at - omission.length
|
84
|
+
stop = if options[:separator]
|
85
|
+
rindex(options[:separator], length_with_room_for_omission) || length_with_room_for_omission
|
86
|
+
else
|
87
|
+
length_with_room_for_omission
|
88
|
+
end
|
89
|
+
|
90
|
+
"#{self[0, stop]}#{omission}"
|
91
|
+
end
|
92
|
+
|
93
|
+
def to_hg(area)
|
94
|
+
Hail::GUI.instance.win.setpos(area[:top], area[:left])
|
95
|
+
Hail::GUI.instance.win.addstr(self.__truncate(area[:width]-3))
|
96
|
+
end
|
97
|
+
end
|
data/lib/hail/mail.rb
ADDED
data/lib/hail.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'net/imap'
|
3
|
+
require 'curses'
|
4
|
+
|
5
|
+
class Hail
|
6
|
+
def initialize()
|
7
|
+
@accounts = Accounts.new
|
8
|
+
|
9
|
+
while true
|
10
|
+
GUI.instance.render
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
require 'hail/accounts'
|
16
|
+
require 'hail/account'
|
17
|
+
require 'hail/gui'
|
18
|
+
require 'hail/mail'
|
metadata
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hail.rb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2015.10.11.20.41
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Adrien Jeser
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-10-11 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: ''
|
14
|
+
email: adrien@jeser.me
|
15
|
+
executables:
|
16
|
+
- hail
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- bin/hail
|
21
|
+
- lib/hail.rb
|
22
|
+
- lib/hail/account.rb
|
23
|
+
- lib/hail/accounts.rb
|
24
|
+
- lib/hail/gui.rb
|
25
|
+
- lib/hail/mail.rb
|
26
|
+
homepage: http://rubygems.org/gems/hail-mua
|
27
|
+
licenses:
|
28
|
+
- GPL3
|
29
|
+
metadata: {}
|
30
|
+
post_install_message:
|
31
|
+
rdoc_options: []
|
32
|
+
require_paths:
|
33
|
+
- lib
|
34
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - ">="
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
requirements: []
|
45
|
+
rubyforge_project:
|
46
|
+
rubygems_version: 2.2.2
|
47
|
+
signing_key:
|
48
|
+
specification_version: 4
|
49
|
+
summary: hail!
|
50
|
+
test_files: []
|