Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[git-p4: depot-paths = "//src/imap_to_rss/dev/": change = 4922]
- Loading branch information
0 parents
commit c22244e
Showing
13 changed files
with
650 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# -*- ruby -*- | ||
|
||
require 'autotest/restart' | ||
|
||
# Autotest.add_hook :initialize do |at| | ||
# at.extra_files << "../some/external/dependency.rb" | ||
# | ||
# at.libs << ":../some/external" | ||
# | ||
# at.add_exception 'vendor' | ||
# | ||
# at.add_mapping(/dependency.rb/) do |f, _| | ||
# at.files_matching(/test_.*rb$/) | ||
# end | ||
# | ||
# %w(TestA TestB).each do |klass| | ||
# at.extra_class_map[klass] = "test/test_misc.rb" | ||
# end | ||
# end | ||
|
||
# Autotest.add_hook :run_command do |at| | ||
# system "rake build" | ||
# end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
=== 1.0.0 / 2009-04-28 | ||
|
||
* 1 major enhancement | ||
|
||
* Birthday! | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
.autotest | ||
History.txt | ||
Manifest.txt | ||
README.txt | ||
Rakefile | ||
bin/imap_to_rss | ||
imap_to_rss.rss | ||
lib/imap_to_rss.rb | ||
lib/imap_to_rss/handler.rb | ||
lib/imap_to_rss/handler/amazon.rb | ||
lib/imap_to_rss/handler/hsbc.rb | ||
lib/imap_to_rss/handler/ups.rb | ||
test/test_imap_to_rss.rb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
= imap_to_rss | ||
|
||
* FIX (url) | ||
|
||
== DESCRIPTION: | ||
|
||
FIX (describe your package) | ||
|
||
== FEATURES/PROBLEMS: | ||
|
||
* FIX (list of features or problems) | ||
|
||
== SYNOPSIS: | ||
|
||
FIX (code sample of usage) | ||
|
||
== REQUIREMENTS: | ||
|
||
* FIX (list of requirements) | ||
|
||
== INSTALL: | ||
|
||
* FIX (sudo gem install, anything else) | ||
|
||
== LICENSE: | ||
|
||
(The MIT License) | ||
|
||
Copyright (c) 2009 FIX | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of this software and associated documentation files (the | ||
'Software'), to deal in the Software without restriction, including | ||
without limitation the rights to use, copy, modify, merge, publish, | ||
distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so, subject to | ||
the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | ||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | ||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# -*- ruby -*- | ||
|
||
require 'rubygems' | ||
require 'hoe' | ||
$:.unshift 'lib' | ||
require 'imap_to_rss' | ||
|
||
Hoe.new 'imap_to_rss', IMAPToRSS::VERSION do |itor| | ||
itor.rubyforge_name = 'seattlerb' | ||
itor.developer 'Eric Hodel', 'drbrain@example.com' | ||
end | ||
|
||
# vim: syntax=Ruby |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/usr/bin/env ruby | ||
|
||
require 'imap_to_rss' | ||
|
||
IMAPToRSS.run ARGV | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?xml version="1.0"?> | ||
<rss version="2.0"> | ||
<channel> | ||
<title>IMAP to RSS</title> | ||
<link>imap://izmunuti.segment7.net</link> | ||
<description>An RSS feed built from your IMAP server</description> | ||
<generator>imap_to_rss version 1.0</generator> | ||
<docs>http://cyber.law.harvard.edu/rss/rss.html</docs> | ||
</channel> | ||
</rss> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
require 'rubygems' | ||
require 'imap_processor' | ||
require 'tmail' | ||
require 'nokogiri' | ||
|
||
## | ||
# IMAPToRSS takes messages from your mailboxes, runs them through handlers, | ||
# then turns them into an RSS feed. Handlers can be added via a plugin system | ||
# so long as they subclass IMAPToRSS::Handler and live in the | ||
# imap_to_rss/handler/ directory. | ||
|
||
class IMAPToRSS < IMAPProcessor | ||
|
||
## | ||
# The version of IMAPToRSS you are using | ||
|
||
VERSION = '1.0' | ||
|
||
## | ||
# An RSS item for the RSS feed. | ||
|
||
RSSItem = Struct.new :title, :description, :author, :pub_date, | ||
:link, :category | ||
|
||
## | ||
# All added RSS items | ||
|
||
attr_reader :rss_items | ||
|
||
## | ||
# Processes command-line options | ||
|
||
def self.process_args(args) | ||
extra_options = { | ||
:Handler => nil, | ||
} | ||
|
||
add_move | ||
|
||
super __FILE__, args, extra_options do |opts, options| | ||
handlers = IMAPToRSS::Handler.handlers.map do |handler| | ||
handler.name.split('::').last | ||
end | ||
|
||
opts.separator '' | ||
opts.separator "Handlers: #{handlers.join ', '}" | ||
opts.separator '' | ||
|
||
opts.on( "--handler=HANDLER", handlers, | ||
"Handler to run", | ||
"Default: all handlers") do |handler| | ||
options[:Handler] = handler | ||
end | ||
end | ||
end | ||
|
||
## | ||
# Creates a new IMAPToRSS and connects to the selected server. | ||
|
||
def initialize(options) | ||
super | ||
|
||
@handlers = [] | ||
@rss_items = [] | ||
|
||
connection = connect options[:Host], options[:Port], options[:SSL], | ||
options[:Username], options[:Password], options[:Auth] | ||
|
||
@imap = connection.imap | ||
end | ||
|
||
## | ||
# Builds an RSS feed from rss_items | ||
|
||
def build_rss | ||
log 'Building RSS feed' | ||
rss = Nokogiri::XML::Builder.new | ||
|
||
rss_items = @rss_items # will work in Nokogiri > 1.2.3 | ||
host = options[:Host] | ||
|
||
rss.rss :version => '2.0' do | ||
rss.channel do | ||
rss.title 'IMAP to RSS' | ||
rss.link "imap://#{host}" | ||
rss.description "An RSS feed built from your IMAP server" | ||
rss.generator "imap_to_rss version #{IMAPToRSS::VERSION}" | ||
rss.docs 'http://cyber.law.harvard.edu/rss/rss.html' | ||
|
||
rss_items.each do |item| | ||
rss.item do | ||
rss.title item.title | ||
rss.description item.description | ||
rss.author item.author | ||
rss.pubDate item.pub_date | ||
rss.link item.link if item.link | ||
rss.category item.category if item.category | ||
end | ||
end | ||
end | ||
end | ||
|
||
open 'imap_to_rss.rss', 'w' do |io| | ||
io.write rss.to_xml | ||
end | ||
|
||
log 'Saved RSS feed' | ||
end | ||
|
||
## | ||
# Processes mailboxes with each handler then writes out the RSS file. | ||
|
||
def run | ||
handlers = IMAPToRSS::Handler.handlers | ||
|
||
handlers.delete_if do |handler| | ||
handler.name.split('::').last != options[:Handler] | ||
end if options[:Handler] | ||
|
||
handlers = handlers.map do |handler| | ||
handler = handler.new | ||
handler.setup self | ||
handler | ||
end | ||
|
||
dest_mailbox = options[:MoveTo] | ||
|
||
@boxes.each do |mailbox| | ||
@imap.select mailbox | ||
log "Selected mailbox #{mailbox}" | ||
|
||
handlers.each do |handler| | ||
log "Running handler #{handler.search.join ' '}" | ||
messages = @imap.search [ | ||
'NOT', 'DELETED', | ||
'NOT', 'KEYWORD', 'IMAP_TO_RSS', | ||
*handler.search | ||
] | ||
|
||
next if messages.empty? | ||
|
||
handled = handler.handle messages | ||
|
||
@imap.store uids, '+FLAGS', %w[IMAP_TO_RSS] | ||
|
||
if dest_mailbox then | ||
@imap.copy handled, dest_mailbox | ||
@imap.store handled, '+FLAGS', [:Deleted] | ||
@imap.expunge | ||
end | ||
end | ||
|
||
build_rss | ||
end | ||
end | ||
|
||
end | ||
|
||
plugins = Gem.find_files 'imap_to_rss/handler/*' | ||
|
||
plugins.each do |plugin| | ||
# strip path info to always require latest | ||
require plugin.sub(/.*(imap_to_rss.handler.*)\.[^.]+$/, '\1') | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
require 'imap_to_rss' | ||
|
||
## | ||
# Base message handler class. Subclass this to define your own handlers. | ||
|
||
class IMAPToRSS::Handler | ||
|
||
## | ||
# IMAP SEARCH command keywords to search | ||
|
||
attr_accessor :search | ||
|
||
@handlers = [] | ||
|
||
## | ||
# Collect handler subclasses | ||
|
||
def self.inherited(subclass) | ||
@handlers << subclass | ||
end | ||
|
||
## | ||
# List of found handlers | ||
|
||
def self.handlers | ||
@handlers | ||
end | ||
|
||
## | ||
# Adds an item to the RSS feed with given parts | ||
|
||
def add_item(title, description, author, pub_date, link = nil, category = nil) | ||
item = IMAPToRSS::RSSItem.new title, description, author, pub_date, link, | ||
category | ||
|
||
@itor.rss_items << item | ||
end | ||
|
||
## | ||
# Delegates to IMAPToRSS#each_message | ||
|
||
def each_message(*args, &block) | ||
@itor.each_message(*args, &block) | ||
end | ||
|
||
def handle(uids) | ||
raise NotImplementedError, 'write me' | ||
end | ||
|
||
## | ||
# Delegates to IMAPToRSS | ||
|
||
def log(*args) | ||
@itor.log(*args) | ||
end | ||
|
||
def setup(imap_to_rss) | ||
@itor = imap_to_rss | ||
@imap = imap_to_rss.imap | ||
end | ||
|
||
end | ||
|
Oops, something went wrong.