end
end
end unless $opts[:no_initial_poll]
-
+
imode.load_threads :num => ibuf.content_height, :when_done => lambda { |num| reporting_thread("poll after loading inbox") { sleep 1; PollManager.poll } unless $opts[:no_threads] || $opts[:no_initial_poll] }
if $opts[:compose]
class Float
def to_s; sprintf '%.2f', self; end
- def to_time_s
- infinite? ? "unknown" : super
- end
+ def to_time_s; infinite? ? "unknown" : super end
end
class Numeric
source.reset!
num_dropped = num_moved = num_scanned = 0
-
+
out_fp = Tempfile.new "sup-sync-back-#{source.id}"
Redwood::PollManager.each_message_from source do |m|
num_scanned += 1
Options:
EOS
- opt :add, "One or more labels (comma-separated) to add to every message from the specified sources", :type => String
- opt :remove, "One or more labels (comma-separated) to remove from every message from the specified sources, if those labels are present", :type => String
+ opt :add, "One or more labels (comma-separated) to add to every message from the specified sources", :default => ""
+ opt :remove, "One or more labels (comma-separated) to remove from every message from the specified sources, if those labels are present", :default => ""
opt :query, "A Sup search query", :type => String
text <<EOS
index = Redwood::Index.new
index.load
- source_ids =
- if opts[:all_sources]
- Redwood::SourceManager.sources
- else
- ARGV.map do |uri|
- Redwood::SourceManager.source_for uri or Trollop::die "Unknown source: #{uri}. Did you add it with sup-add first?"
- end
+ source_ids = if opts[:all_sources]
+ Redwood::SourceManager.sources
+ else
+ ARGV.map do |uri|
+ Redwood::SourceManager.source_for uri or Trollop::die "Unknown source: #{uri}. Did you add it with sup-add first?"
+ end
end.map { |s| s.id }
Trollop::die "nothing to do: no sources" if source_ids.empty?
vars = props.map { |p| "@#{p}" }
klass = self
path = klass.name.gsub(/::/, "/")
-
+
klass.instance_eval do
define_method(:to_yaml_properties) { vars }
define_method(:to_yaml_type) { "!#{Redwood::YAML_DOMAIN},#{Redwood::YAML_DATE}/#{path}" }
end
if answer
- answer =
+ answer =
if answer.empty?
spawn_modal "file browser", FileBrowserMode.new
elsif File.directory?(answer)
def ask_for_contacts domain, question, default_contacts=[]
default = default_contacts.map { |s| s.to_s }.join(" ")
default += " " unless default.empty?
-
+
recent = Index.load_contacts(AccountManager.user_emails, :num => 10).map { |c| [c.full_address, c.email] }
contacts = ContactManager.contacts.map { |c| [ContactManager.alias_for(c), c.full_address, c.email] }
output = run_gpg "--decrypt #{payload_fn.path}"
if $?.success?
- decrypted_payload, sig_lines =
- if output =~ /\A(.*?)((^gpg: .*$)+)\Z/m
- [$1, $2]
+ decrypted_payload, sig_lines = if output =~ /\A(.*?)((^gpg: .*$)+)\Z/m
+ [$1, $2]
+ else
+ [output, nil]
+ end
+
+ sig = if sig_lines # encrypted & signed
+ if sig_lines =~ /^gpg: (Good signature from .*$)/
+ Chunk::CryptoNotice.new :valid, $1, sig_lines.split("\n")
else
- [output, nil]
- end
-
- sig =
- if sig_lines # encrypted & signed
- if sig_lines =~ /^gpg: (Good signature from .*$)/
- Chunk::CryptoNotice.new :valid, $1, sig_lines.split("\n")
- else
- Chunk::CryptoNotice.new :invalid, $1, sig_lines.split("\n")
- end
+ Chunk::CryptoNotice.new :invalid, $1, sig_lines.split("\n")
end
+ end
notice = Chunk::CryptoNotice.new :valid, "This message has been decrypted for display"
[RMail::Parser.read(decrypted_payload), sig, notice]
def unknown_status lines=[]
Chunk::CryptoNotice.new :unknown, "Unable to determine validity of cryptographic signature", lines
end
-
+
def cant_find_binary
["Can't find gpg binary in path."]
end
raise OutOfSyncSourceError, "mbox file is smaller than last recorded message offset. Messages have probably been deleted by another client."
end
end
-
+
def start_offset; 0; end
def end_offset; File.size @f; end
class ScrollMode < Mode
## we define topline and botline as the top and bottom lines of any
## content in the currentview.
-
+
## we left leftcol and rightcol as the left and right columns of any
## content in the current view. but since we're operating in a
## line-centric fashion, rightcol is always leftcol + the buffer
raise "nil text for color '#{color}'" if text.nil? # good for debugging
l = text.display_length
no_fill = i != a.size - 1
-
+
if xpos + l < @leftcol
buffer.write ln - @topline, 0, "", :color => color,
:highlight => opts[:highlight]
buffer.mark_dirty if buffer
super()
end
-
+
def save_to_disk
fn = BufferManager.ask_for_filename :filename, "Save to file: ", @filename
save_to_file(fn) { |f| f.puts text } if fn
@lines << @text.length
if buffer
ensure_mode_validity
- buffer.mark_dirty
+ buffer.mark_dirty
end
end
@thread = nil
@last_poll = nil
@polling = false
-
+
self.class.i_am_the_instance self
end
## To write a new source, subclass this class, and implement:
##
## - start_offset
- ## - end_offset (exclusive!)
+ ## - end_offset (exclusive!) (or, #done?)
## - load_header offset
## - load_message offset
## - raw_header offset
## - raw_message offset
- ## - check
+ ## - check (optional)
## - next (or each, if you prefer): should return a message and an
## array of labels.
##
@dirty = false
end
+ ## overwrite me if you have a disk incarnation (currently used only for sup-sync-back)
def file_path; nil end
def to_s; @uri.to_s; end
## to proactively notify the user of any source problems.
def check; end
+ ## yields successive offsets and labels, starting at #cur_offset.
+ ##
+ ## when implementing a source, you can overwrite either #each or #next. the
+ ## default #each just calls next over and over.
def each
self.cur_offset ||= start_offset
until done?
- n, labels = self.next
- raise "no message" unless n
- yield n, labels
+ offset, labels = self.next
+ yield offset, labels
end
end
- ## read a raw email header from a filehandle (or anything that responds to
- ## #gets), and turn it into a hash of key-value pairs.
+ ## utility method to read a raw email header from an IO stream and turn it
+ ## into a hash of key-value pairs. minor special semantics for certain headers.
##
- ## WARNING! THIS IS A SPEED-CRITICAL SECTION. Everything you do here will have
- ## a significant effect on Sup's processing speed of email from ALL sources.
+ ## THIS IS A SPEED-CRITICAL SECTION. Everything you do here will have a
+ ## significant effect on Sup's processing speed of email from ALL sources.
## Little things like string interpolation, regexp interpolation, += vs <<,
## all have DRAMATIC effects. BE CAREFUL WHAT YOU DO!
def self.parse_raw_email_header f
case line
## these three can occur multiple times, and we want the first one
when /^(Delivered-To|X-Original-To|Envelope-To):\s*(.*?)\s*$/i; header[last = $1.downcase] ||= $2
- ## mark this guy specially. not sure why i care.
+ ## regular header: overwrite (not that we should see more than one)
+ ## TODO: figure out whether just using the first occurrence changes
+ ## anything (which would simplify the logic slightly)
when /^([^:\s]+):\s*(.*?)\s*$/i; header[last = $1.downcase] = $2
- when /^\r*$/; break
+ when /^\r*$/; break # blank line signifies end of header
else
if last
header[last] << " " unless header[last].empty?
## convenience function
def parse_raw_email_header f; self.class.parse_raw_email_header f end
-
+
def Source.expand_filesystem_uri uri
uri.gsub "~", File.expand_path("~")
end
def toggle_label label
if has_label? label
remove_label label
- return false
+ false
else
apply_label label
- return true
+ true
end
end
def set_labels l; each { |m, *o| m && m.labels = l }; end
-
def has_label? t; any? { |m, *o| m && m.has_label?(t) }; end
def save_state index; each { |m, *o| m && m.save_state(index) }; end
end
def latest_message
- inject(nil) do |a, b|
+ inject(nil) do |a, b|
b = b.first
if a.nil?
b
@id = id
@message, @parent, @thread = nil, nil, nil
@children = []
- end
+ end
def each_with_stuff parent=nil
yield self, 0, parent
newpos = case state
when :escaped_instring, :escaped_outstring then pos
else index(/[,"\\]/, pos)
- end
-
+ end
+
if newpos
char = self[newpos]
else
def has_errors?; !@error.nil?; end
def method_missing m, *a, &b; __pass m, *a, &b end
-
+
def id; __pass :id; end
def to_s; __pass :to_s; end
def to_yaml x; __pass :to_yaml, x; end