podgraph 0.1.5 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +49 -0
- data/package.gemspec +33 -0
- data/podgraph +5 -0
- data/podgraph.rb +105 -0
- metadata +64 -88
- data/LICENSE +0 -22
- data/NEWS +0 -41
- data/README.rdoc +0 -99
- data/Rakefile +0 -44
- data/TODO +0 -7
- data/bin/podgraph +0 -78
- data/lib/podgraph/meta.rb +0 -9
- data/lib/podgraph/posterous.rb +0 -163
- data/lib/podgraph/trestle.rb +0 -216
- data/test/.document +0 -0
- data/test/blue.png +0 -0
- data/test/config.yaml +0 -3
- data/test/empty.html +0 -0
- data/test/garbage_01.html +0 -1
- data/test/garbage_02.html +0 -1
- data/test/garbage_03.html +0 -8
- data/test/garbage_04.html +0 -9
- data/test/helper.rb +0 -3
- data/test/helper_trestle.rb +0 -37
- data/test/mechanical-turk/1.html +0 -329
- data/test/mechanical-turk/2.html +0 -320
- data/test/mechanical-turk/3.html +0 -320
- data/test/mechanical-turk/Baby-Bunnie.jpg +0 -0
- data/test/mechanical-turk/config.yaml +0 -3
- data/test/mechanical-turk/sun.jpg +0 -0
- data/test/nosubject.html +0 -5
- data/test/rake_git.rb +0 -36
- data/test/related.html +0 -15
- data/test/simple.html +0 -9
- data/test/test_mime.rb +0 -132
- data/test/yellow.png +0 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: eb7e5f6fbf4e7cd487ad65da35ae181eee91abccc4c0c31a81cb8c9e550fdedc
|
4
|
+
data.tar.gz: 9132ccc5759c30bcc8d1a8dbd010263d0a2b93b98238dc4eeb4bc9980adf2e42
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7bbd58c071ad129881cd197e93ba6d1b93bf602c4c046eb438fc903e9366d4be70c99f31eebf34f71dc354a8a32b0c954e96c5bc08b22c44d70d350dc7219011
|
7
|
+
data.tar.gz: d855a06bd1d36e7cf66b01d135818841387920fa1728288f0c8e84ddbe21158f922cd4a02358d5929f847e0a00001b8ec4bf466aecd58614f2472c9f1e243e2d
|
data/README.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Podgraph
|
2
|
+
|
3
|
+
Post to Blogger or Wordpress via email; inline local images.
|
4
|
+
|
5
|
+
Creates a special 'Multipart/Related' email from an html input.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Ruby 2.3+
|
10
|
+
|
11
|
+
$ gem install podgraph
|
12
|
+
|
13
|
+
## Usage
|
14
|
+
|
15
|
+
Blogger:
|
16
|
+
|
17
|
+
$ pandoc post.md | podgraph | sendmail -i XXX@blogger.com
|
18
|
+
|
19
|
+
Wordpress:
|
20
|
+
|
21
|
+
$ pandoc post.md | podgraph XXX@post.wordpress.com | sendmail -it
|
22
|
+
|
23
|
+
## Bugs
|
24
|
+
|
25
|
+
* WP strips out inlined svgs
|
26
|
+
|
27
|
+
## History
|
28
|
+
|
29
|
+
Once upon a time there was a blogging platform called Posterous. Its
|
30
|
+
main selling point was a 'post by email' feature. You could even email
|
31
|
+
images & they would appear neatly inlined within paragraphs (if your
|
32
|
+
email client supported composing such an email; many did).
|
33
|
+
|
34
|
+
Podgraph was initially written as a 'client' for Posterous: you wrote
|
35
|
+
your blog post in reStructuredText, converted it to html, piped the
|
36
|
+
result to 'podgraph' cmd, which grabbed all local images mentioned in
|
37
|
+
the html, made a 'Multipart/Related' email from them & delivered it to
|
38
|
+
sendmail.
|
39
|
+
|
40
|
+
Posterous has long been dead & gone. The 'post by email' feature was
|
41
|
+
copied by Blogger & Wordpress.
|
42
|
+
|
43
|
+
Recently I've tried to reuse podgraph for Blogger, but that endeavour
|
44
|
+
miscarried, for the script appeared to be hopelessly broken. Version
|
45
|
+
1.0.0 is a total rewrite.
|
46
|
+
|
47
|
+
## License
|
48
|
+
|
49
|
+
MIT
|
data/package.gemspec
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.version = '1.0.1'
|
3
|
+
|
4
|
+
s.name = 'podgraph'
|
5
|
+
s.summary = "Post to Blogger or Wordpress via email; inline local images"
|
6
|
+
s.author = 'Alexander Gromnitsky'
|
7
|
+
s.email = 'alexander.gromnitsky@gmail.com'
|
8
|
+
s.homepage = 'https://github.com/gromnitsky/podgraph'
|
9
|
+
s.license = 'MIT'
|
10
|
+
s.files = [
|
11
|
+
'podgraph',
|
12
|
+
'podgraph.rb',
|
13
|
+
'package.gemspec',
|
14
|
+
'README.md',
|
15
|
+
]
|
16
|
+
|
17
|
+
s.require_paths = ['.']
|
18
|
+
s.bindir = '.'
|
19
|
+
s.executables = ['podgraph']
|
20
|
+
|
21
|
+
s.add_runtime_dependency 'mail', '~> 2.7.0'
|
22
|
+
s.add_runtime_dependency 'nokogiri', '~> 1.8.2'
|
23
|
+
|
24
|
+
s.required_ruby_version = '>= 2.3.0'
|
25
|
+
|
26
|
+
s.post_install_message = <<~END
|
27
|
+
*************************************************************************
|
28
|
+
If you were using podgraph-0.x, please read
|
29
|
+
#{s.homepage},
|
30
|
+
for it's a different program now, totally incompatible w/ 0.x releases.
|
31
|
+
*************************************************************************
|
32
|
+
END
|
33
|
+
end
|
data/podgraph
ADDED
data/podgraph.rb
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'digest'
|
3
|
+
require 'base64'
|
4
|
+
|
5
|
+
require 'nokogiri'
|
6
|
+
require 'mail'
|
7
|
+
|
8
|
+
module Podgraph; end
|
9
|
+
|
10
|
+
class Podgraph::Transformer
|
11
|
+
def initialize html
|
12
|
+
@doc = Nokogiri.HTML html
|
13
|
+
svg!
|
14
|
+
pre!
|
15
|
+
@images = raster_images!
|
16
|
+
end
|
17
|
+
attr_reader :images
|
18
|
+
|
19
|
+
# inline svg; I've tried a straight xml insertion, but Blogger's freaked out
|
20
|
+
def svg!
|
21
|
+
attr = ->(node) { ['src', 'data'].find {|k| node[k]} }
|
22
|
+
@doc.css('img,iframe,embed,object[type="image/svg+xml"]').select do |node|
|
23
|
+
src = attr.call node
|
24
|
+
Transformer.local_img?(node, ['src', 'data']) && MiniMime.lookup_by_filename(node[src])&.content_type == 'image/svg+xml'
|
25
|
+
end.each do |node|
|
26
|
+
src = attr.call node
|
27
|
+
node[src] = "data:image/svg+xml;base64,#{Base64.strict_encode64(File.read node[src])}"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
# replace every newline in <pre> with <br>, because Blogger
|
32
|
+
def pre!
|
33
|
+
@doc.css('pre').each do |node|
|
34
|
+
text = node.to_s.gsub(/\n/, '<br>')
|
35
|
+
node.replace Nokogiri::HTML.fragment text
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# return local images; relink each affecter <img>
|
40
|
+
def raster_images!
|
41
|
+
images = {}
|
42
|
+
@doc.css('img').select do |img|
|
43
|
+
Transformer.local_img? img
|
44
|
+
end.each do |img|
|
45
|
+
fail "unsupported file format: #{img['src']}" if !MiniMime.lookup_by_filename img['src']
|
46
|
+
|
47
|
+
sha1 = Digest::SHA1.hexdigest File.read img['src']
|
48
|
+
images[sha1] ||= { name: img['src'] }
|
49
|
+
img['src'] = "cid:#{sha1}"
|
50
|
+
end
|
51
|
+
images
|
52
|
+
end
|
53
|
+
|
54
|
+
def subject
|
55
|
+
@subject ||= begin
|
56
|
+
node = @doc.css('h1,h2,h3,h4').first
|
57
|
+
return 'no subject' unless node
|
58
|
+
text = node.text
|
59
|
+
node.remove
|
60
|
+
text
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def html; @doc.to_s; end
|
65
|
+
|
66
|
+
def self.local_img? node, attr = ['src'] # TODO: allow file:// scheme
|
67
|
+
attr.any? do |k|
|
68
|
+
node[k] && node[k].strip.size > 0 &&
|
69
|
+
!node[k].start_with?('data:') && !URI(node[k]).scheme
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
class Podgraph::MailGenerator
|
75
|
+
def initialize tr, recipients = []
|
76
|
+
@tr = tr
|
77
|
+
@mail = Mail.new
|
78
|
+
@mail.to = recipients
|
79
|
+
@mail.subject = tr.subject
|
80
|
+
tr.images.empty? ? simple : multipart_related
|
81
|
+
end
|
82
|
+
|
83
|
+
def to_s; @mail.to_s; end
|
84
|
+
|
85
|
+
def simple
|
86
|
+
@mail.content_disposition 'inline'
|
87
|
+
@mail.content_type 'text/html; charset="UTF-8"'
|
88
|
+
@mail.body @tr.html
|
89
|
+
end
|
90
|
+
|
91
|
+
def multipart_related
|
92
|
+
@mail.content_type 'Multipart/Related'
|
93
|
+
html = @tr.html
|
94
|
+
@mail.html_part do
|
95
|
+
content_type 'text/html; charset=UTF-8'
|
96
|
+
body html
|
97
|
+
end
|
98
|
+
|
99
|
+
@tr.images.each do |k,v|
|
100
|
+
@mail.add_file v[:name]
|
101
|
+
@mail.parts.last.content_disposition 'inline'
|
102
|
+
@mail.parts.last.content_id "<#{k}>"
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
metadata
CHANGED
@@ -1,106 +1,82 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: podgraph
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
version: 0.1.5
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.1
|
6
5
|
platform: ruby
|
7
|
-
authors:
|
6
|
+
authors:
|
8
7
|
- Alexander Gromnitsky
|
9
8
|
autorequire:
|
10
|
-
bindir:
|
9
|
+
bindir: "."
|
11
10
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
- !ruby/object:Gem::Dependency
|
11
|
+
date: 2018-05-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
16
14
|
name: mail
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 2.7.0
|
20
|
+
type: :runtime
|
17
21
|
prerelease: false
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 2.7.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: nokogiri
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.8.2
|
24
34
|
type: :runtime
|
25
|
-
version_requirements: *id001
|
26
|
-
- !ruby/object:Gem::Dependency
|
27
|
-
name: git
|
28
35
|
prerelease: false
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
type: :development
|
36
|
-
version_requirements: *id002
|
37
|
-
description: Adequately scans XHTML for local inline images and appends them to the mail.
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.8.2
|
41
|
+
description:
|
38
42
|
email: alexander.gromnitsky@gmail.com
|
39
|
-
executables:
|
43
|
+
executables:
|
40
44
|
- podgraph
|
41
45
|
extensions: []
|
42
|
-
|
43
46
|
extra_rdoc_files: []
|
44
|
-
|
45
|
-
|
46
|
-
-
|
47
|
-
-
|
48
|
-
-
|
49
|
-
-
|
50
|
-
|
51
|
-
|
52
|
-
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
-
|
63
|
-
|
64
|
-
|
65
|
-
- test/mechanical-turk/1.html
|
66
|
-
- test/mechanical-turk/2.html
|
67
|
-
- test/mechanical-turk/3.html
|
68
|
-
- test/mechanical-turk/Baby-Bunnie.jpg
|
69
|
-
- test/mechanical-turk/config.yaml
|
70
|
-
- test/mechanical-turk/sun.jpg
|
71
|
-
- test/nosubject.html
|
72
|
-
- test/rake_git.rb
|
73
|
-
- test/related.html
|
74
|
-
- test/simple.html
|
75
|
-
- test/test_mime.rb
|
76
|
-
- test/yellow.png
|
77
|
-
homepage: http://github.com/gromnitsky/podgraph
|
78
|
-
licenses: []
|
79
|
-
|
80
|
-
post_install_message:
|
81
|
-
rdoc_options:
|
82
|
-
- -m
|
83
|
-
- Podgraph
|
84
|
-
require_paths:
|
85
|
-
- lib
|
86
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
87
|
-
none: false
|
88
|
-
requirements:
|
47
|
+
files:
|
48
|
+
- "./podgraph"
|
49
|
+
- README.md
|
50
|
+
- package.gemspec
|
51
|
+
- podgraph
|
52
|
+
- podgraph.rb
|
53
|
+
homepage: https://github.com/gromnitsky/podgraph
|
54
|
+
licenses:
|
55
|
+
- MIT
|
56
|
+
metadata: {}
|
57
|
+
post_install_message: |
|
58
|
+
*************************************************************************
|
59
|
+
If you were using podgraph-0.x, please read
|
60
|
+
https://github.com/gromnitsky/podgraph,
|
61
|
+
for it's a different program now, totally incompatible w/ 0.x releases.
|
62
|
+
*************************************************************************
|
63
|
+
rdoc_options: []
|
64
|
+
require_paths:
|
65
|
+
- "."
|
66
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
89
68
|
- - ">="
|
90
|
-
- !ruby/object:Gem::Version
|
91
|
-
version:
|
92
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
-
|
94
|
-
requirements:
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: 2.3.0
|
71
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
95
73
|
- - ">="
|
96
|
-
- !ruby/object:Gem::Version
|
97
|
-
version:
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
98
76
|
requirements: []
|
99
|
-
|
100
77
|
rubyforge_project:
|
101
|
-
rubygems_version:
|
78
|
+
rubygems_version: 2.7.6
|
102
79
|
signing_key:
|
103
|
-
specification_version:
|
104
|
-
summary:
|
105
|
-
test_files:
|
106
|
-
- test/test_mime.rb
|
80
|
+
specification_version: 4
|
81
|
+
summary: Post to Blogger or Wordpress via email; inline local images
|
82
|
+
test_files: []
|
data/LICENSE
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
(The MIT License)
|
2
|
-
|
3
|
-
Copyright (c) 2010 Alexander Gromnitsky.
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
-
a copy of this software and associated documentation files (the
|
7
|
-
'Software'), to deal in the Software without restriction, including
|
8
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
-
permit persons to whom the Software is furnished to do so, subject to
|
11
|
-
the following conditions:
|
12
|
-
|
13
|
-
The above copyright notice and this permission notice shall be
|
14
|
-
included in all copies or substantial portions of the Software.
|
15
|
-
|
16
|
-
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
17
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
19
|
-
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
20
|
-
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
21
|
-
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
22
|
-
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/NEWS
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
-*- text -*-
|
2
|
-
|
3
|
-
0.1.5
|
4
|
-
-----
|
5
|
-
|
6
|
-
Fri Apr 29 00:31:16 EEST 2011
|
7
|
-
|
8
|
-
- Added '--to' & '--from' command line options.
|
9
|
-
|
10
|
-
0.0.5
|
11
|
-
-----
|
12
|
-
|
13
|
-
Wed Apr 20 21:58:27 EEST 2011
|
14
|
-
|
15
|
-
- If no input file is specified, read stdin.
|
16
|
-
|
17
|
-
- Repackaged under RVM in fedora.
|
18
|
-
|
19
|
-
0.0.4
|
20
|
-
-----
|
21
|
-
|
22
|
-
Tue Apr 19 19:01:14 EEST 2011
|
23
|
-
|
24
|
-
- Fixed one RE to support https:// images.
|
25
|
-
|
26
|
-
- Dropped activesupport dependency.
|
27
|
-
|
28
|
-
- Injected falsework's naive template.
|
29
|
-
|
30
|
-
0.0.3
|
31
|
-
-----
|
32
|
-
|
33
|
-
- added missing activesupport dependency (btw, activesupport 3.0.0
|
34
|
-
requires i18n (run 'gem install i18n', for some reason this dependency
|
35
|
-
isn't listed in the gem).
|
36
|
-
|
37
|
-
0.0.2
|
38
|
-
-----
|
39
|
-
|
40
|
-
- nailed the mail gem to explicit version 2.1.3, because the current
|
41
|
-
2.2.0 introduced some weird bugs.
|
data/README.rdoc
DELETED
@@ -1,99 +0,0 @@
|
|
1
|
-
= Name
|
2
|
-
|
3
|
-
podgraph -- Create an email from XHTML + inline images and send it to
|
4
|
-
posterous.com.
|
5
|
-
|
6
|
-
= Synopsis
|
7
|
-
|
8
|
-
podgraph [options] [file.html]
|
9
|
-
|
10
|
-
= Description
|
11
|
-
|
12
|
-
It is a simple program that reads a XHTML file (or stdin), extracts
|
13
|
-
subject and body from the file, constructs an email and delivers it to
|
14
|
-
local MTA.
|
15
|
-
|
16
|
-
The options are as follows:
|
17
|
-
|
18
|
-
-v Be more verbose.
|
19
|
-
-S Don't send, just dump the mail to stdout.
|
20
|
-
-m ARG 1 of modes: related, mixed.
|
21
|
-
--from EMAIL 'From' address
|
22
|
-
--to EMAIL 'To' address
|
23
|
-
|
24
|
-
The file is supposed to be a XHTML generated by python's docutils from
|
25
|
-
reStructuredText. The idea is:
|
26
|
-
|
27
|
-
1. Write a post (for example, for posterous.com) in reStructuredText in
|
28
|
-
Emacs.
|
29
|
-
|
30
|
-
2. Convert it with help of docutils to the XHTML.
|
31
|
-
|
32
|
-
3. Finally, create a proper MIME mail from the raw XHTML and send it to
|
33
|
-
posterous.com.
|
34
|
-
|
35
|
-
<em>Step 3 is what podgraph does.</em>
|
36
|
-
|
37
|
-
== Features
|
38
|
-
|
39
|
-
* Generates mail with inline images if it can found links to local
|
40
|
-
images in the XHTML file.
|
41
|
-
|
42
|
-
* Charset of 'text/html' portion of a mail is always UTF-8.
|
43
|
-
|
44
|
-
= Exit status
|
45
|
-
|
46
|
-
Program exits 0 on success (something was generated or even delivered),
|
47
|
-
or >= 1 if en error occurs.
|
48
|
-
|
49
|
-
= Examples
|
50
|
-
|
51
|
-
Create a config.yaml file in the directory with your writings. For
|
52
|
-
example:
|
53
|
-
|
54
|
-
% cd ~/lib/writing/posterous
|
55
|
-
% cat config.yaml
|
56
|
-
:to: post@posterous.com
|
57
|
-
:from: me@example.org
|
58
|
-
|
59
|
-
('--to' & '--from' command line options override values in config.yaml.)
|
60
|
-
|
61
|
-
Start writing a .rest file:
|
62
|
-
|
63
|
-
% emacsclient 0001.rest &
|
64
|
-
|
65
|
-
[...]
|
66
|
-
|
67
|
-
To give podgraph a chance to find a subject for the mail, write .rest
|
68
|
-
file as:
|
69
|
-
|
70
|
-
This is a subject
|
71
|
-
-----------------
|
72
|
-
|
73
|
-
My usual reStructuredText.
|
74
|
-
|
75
|
-
Or in another words, the first 2 tags in the body of the the XHTML must
|
76
|
-
be:
|
77
|
-
|
78
|
-
<div><h1>My subject</h1> [...]
|
79
|
-
|
80
|
-
Convert it to XHTML:
|
81
|
-
|
82
|
-
% rst2html < 0001.rest > 0001.html
|
83
|
-
|
84
|
-
Send to posterous.com:
|
85
|
-
|
86
|
-
% podgraph 0001.html
|
87
|
-
|
88
|
-
Also, you can preview the mail without sending it:
|
89
|
-
|
90
|
-
% podgraph -S 0001.html
|
91
|
-
|
92
|
-
If you have links to local images in your .rest file (and
|
93
|
-
correspondingly in .html) then podgraph will include images in the mail
|
94
|
-
as inline images. But if you don't want this and want images to become a
|
95
|
-
typical gallery on posterous.com, run:
|
96
|
-
|
97
|
-
% podgraph -m mixed 0001.html
|
98
|
-
|
99
|
-
This will generate the mail with usual boring attachments.
|
data/Rakefile
DELETED
@@ -1,44 +0,0 @@
|
|
1
|
-
# -*-ruby-*-
|
2
|
-
|
3
|
-
require 'rake'
|
4
|
-
require 'rake/gempackagetask'
|
5
|
-
require 'rake/clean'
|
6
|
-
require 'rake/rdoctask'
|
7
|
-
require 'rake/testtask'
|
8
|
-
|
9
|
-
require_relative 'lib/podgraph/meta'
|
10
|
-
require_relative 'test/rake_git'
|
11
|
-
|
12
|
-
spec = Gem::Specification.new do |s|
|
13
|
-
s.name = Podgraph::Meta::NAME
|
14
|
-
s.version = Podgraph::Meta::VERSION
|
15
|
-
s.summary = 'Creates a MIME mail from a XHTML source and delivers it to Posterous.com.'
|
16
|
-
s.description = 'Adequately scans XHTML for local inline images and appends them to the mail.'
|
17
|
-
s.author = Podgraph::Meta::AUTHOR
|
18
|
-
s.email = Podgraph::Meta::EMAIL
|
19
|
-
s.homepage = Podgraph::Meta::HOMEPAGE
|
20
|
-
s.platform = Gem::Platform::RUBY
|
21
|
-
s.required_ruby_version = '>= 1.9.2'
|
22
|
-
s.files = git_ls('.')
|
23
|
-
s.executables = [s.name]
|
24
|
-
|
25
|
-
s.test_files = FileList['test/test_*.rb']
|
26
|
-
s.rdoc_options << '-m' << 'Podgraph'
|
27
|
-
|
28
|
-
s.add_dependency('mail', '~> 2.3.0')
|
29
|
-
s.add_development_dependency('git', '>= 1.2.5')
|
30
|
-
end
|
31
|
-
|
32
|
-
Rake::GemPackageTask.new(spec).define
|
33
|
-
|
34
|
-
task default: [:repackage]
|
35
|
-
|
36
|
-
Rake::RDocTask.new('doc') do |rd|
|
37
|
-
rd.main = "Podgraph"
|
38
|
-
rd.rdoc_files.include("lib/**/*.rb")
|
39
|
-
end
|
40
|
-
|
41
|
-
Rake::TestTask.new do |t|
|
42
|
-
t.test_files = FileList['test/test_*.rb']
|
43
|
-
t.verbose = true
|
44
|
-
end
|
data/TODO
DELETED
data/bin/podgraph
DELETED
@@ -1,78 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# -*- ruby -*-
|
3
|
-
|
4
|
-
require_relative '../lib/podgraph/posterous'
|
5
|
-
|
6
|
-
$conf = {}
|
7
|
-
u = Trestle.new $conf
|
8
|
-
|
9
|
-
$conf[:send?] = true
|
10
|
-
$conf[:mailconfig] = 'config.yaml'
|
11
|
-
$conf[:modes] = %w(related mixed)
|
12
|
-
$conf[:mode] = 'related'
|
13
|
-
$conf[:to] = nil
|
14
|
-
$conf[:from] = nil
|
15
|
-
$conf[:banner] = "#{File.basename($0)} [options] [file.html]\nType 'ri #{Podgraph::Meta::NAME.capitalize}' for the help."
|
16
|
-
$conf[:input] = nil
|
17
|
-
|
18
|
-
def mailconfig_load
|
19
|
-
begin
|
20
|
-
myconf = YAML.load_file($conf[:mailconfig])
|
21
|
-
rescue
|
22
|
-
abort("cannot parse #{$conf[:mailconfig]} in the current directory")
|
23
|
-
end
|
24
|
-
%w(to from).each { |i|
|
25
|
-
if ! $conf[i.to_sym]
|
26
|
-
Trestle.errx(1, "missing #{i} in #{$conf[:mailconfig]}") if ! myconf.key?(i.to_sym)
|
27
|
-
$conf[i.to_sym] = myconf[i.to_sym]
|
28
|
-
end
|
29
|
-
}
|
30
|
-
end
|
31
|
-
|
32
|
-
def mail_addr_valid?(t)
|
33
|
-
return false if t =~ /^\s*$/ # why Mail::Address doesn't handle this?
|
34
|
-
begin
|
35
|
-
Mail::Address.new t
|
36
|
-
rescue
|
37
|
-
return false
|
38
|
-
end
|
39
|
-
return true
|
40
|
-
end
|
41
|
-
|
42
|
-
# ---
|
43
|
-
|
44
|
-
u.config_parse(['foobar']) {|src|
|
45
|
-
o = u.cl_parse(src) # create an OptionParser object
|
46
|
-
o.on('--from EMAIL', "'From' address") { |v| $conf[:from] = v if mail_addr_valid?(v) }
|
47
|
-
o.on('--to EMAIL', "'To' address") { |v| $conf[:to] = v if mail_addr_valid?(v) }
|
48
|
-
o.on('-c ARG', "Use another configuration file instead of",
|
49
|
-
$conf[:mailconfig]) { |v| $conf[:mailconfig] = v }
|
50
|
-
o.on('-S', "Don't send, just dump the mail to stdout") { |v| $conf[:send?] = false }
|
51
|
-
o.on('-m ARG', "Select mode: #{$conf[:modes].join(', ')}") { |v| $conf[:mode] = v }
|
52
|
-
u.cl_parse(src, o) # run cl parser
|
53
|
-
}
|
54
|
-
|
55
|
-
#pp $conf
|
56
|
-
|
57
|
-
ARGV.size < 1 ? $conf[:input] = STDIN : $conf[:input] = ARGV[0]
|
58
|
-
mailconfig_load if (!$conf[:from] || !$conf[:to])
|
59
|
-
|
60
|
-
begin
|
61
|
-
p = Podgraph::Posterous.new(u, $conf[:input], $conf[:to], $conf[:from], $conf[:mode])
|
62
|
-
u.veputs(2, "o: #{p.o}".to_s.encode('koi8-u'))
|
63
|
-
mail = p.generate
|
64
|
-
rescue
|
65
|
-
Trestle.errx(1, "HTML parsing failed: #{$!}")
|
66
|
-
end
|
67
|
-
|
68
|
-
if ! $conf[:send?]
|
69
|
-
puts mail.to_s
|
70
|
-
exit 0
|
71
|
-
end
|
72
|
-
|
73
|
-
begin
|
74
|
-
mail.delivery_method :sendmail
|
75
|
-
mail.deliver
|
76
|
-
rescue
|
77
|
-
Trestle.errx(1, "cannot send mail: #{$!}")
|
78
|
-
end
|