X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=bin%2Fsup-add;h=e27a0ebf6ff446a9347d4fd8937653ab45b97db8;hb=da1abd360e25011bdbe23b9194f926f29b8aef44;hp=5cb8f9285a5ce6ba601522e29c5fe5448878f841;hpb=f0611494a67c2018ea3c4e179faaf3c93694837c;p=sup diff --git a/bin/sup-add b/bin/sup-add old mode 100644 new mode 100755 index 5cb8f92..e27a0eb --- a/bin/sup-add +++ b/bin/sup-add @@ -6,22 +6,19 @@ require 'highline/import' require 'trollop' require "sup" -Thread.abort_on_exception = true # make debugging possible - $opts = Trollop::options do version "sup-add (sup #{Redwood::VERSION})" banner <+ + sup-add [options] + -where + is one or more sources. +where + is one or more source URIs. For mbox files on local disk, use the form: + mbox:, or mbox:// -or simply - For mbox files on remote machines, use the form: mbox+ssh:/// @@ -32,13 +29,15 @@ For IMAP folders, use the form (note no username or password!): imaps:/// # secure, "INBOX" folder imaps:/// # secure, arbitrary folder -For gmail accounts, use the form (note no username or password!): - gmail:// +For Maildir folders, use the form: + maildir:; or + maildir:// Options are: EOS opt :archive, "Automatically archive all new messages from these sources." opt :unusual, "Do not automatically poll these sources for new messages." + opt :labels, "A comma-separated set of labels to apply to all messages from this source", :type => String opt :force_new, "Create a new account for this source, even if one already exists." end @@ -78,32 +77,47 @@ end $terminal.wrap_at = :auto Redwood::start -index = Redwood::Index.new -index.load - -ARGV.each do |uri| - uri = "mbox://#{uri}" unless uri =~ %r!://! - if !$opts[:force_new] && index.source_for(uri) - say "Already know about #{uri}; skipping." - next - end - source = - case uri - when %r!^mbox\+ssh://! - say "For SSH connections, if you will use public key authentication, you may leave the username and password blank." - say "" - username, password = get_login_info uri, index.sources - Redwood::MBox::SSHLoader.new(uri, username, password, nil, !$opts[:unusual], $opts[:archive]) - when %r!^imaps?://! - username, password = get_login_info uri, index.sources - Redwood::IMAP.new(uri, username, password, nil, !$opts[:unusual], $opts[:archive]) - else - Redwood::MBox::Loader.new(uri, nil, !$opts[:unusual], $opts[:archive]) +index = Redwood::Index.init + +index.lock_interactively or exit + +begin + Redwood::SourceManager.load_sources + + ARGV.each do |uri| + labels = $opts[:labels] ? $opts[:labels].split(/\s*,\s*/).uniq : [] + + if !$opts[:force_new] && Redwood::SourceManager.source_for(uri) + say "Already know about #{uri}; skipping." + next end - say "Adding #{source}..." - index.add_source source -end -say "Saving source list..." -index.save -Redwood::finish + parsed_uri = URI(uri) + + source = + case parsed_uri.scheme + when "mbox+ssh" + say "For SSH connections, if you will use public key authentication, you may leave the username and password blank." + say "" + username, password = get_login_info uri, Redwood::SourceManager.sources + Redwood::MBox::SSHLoader.new uri, username, password, nil, !$opts[:unusual], $opts[:archive], nil, labels + when "imap", "imaps" + username, password = get_login_info uri, Redwood::SourceManager.sources + Redwood::IMAP.new uri, username, password, nil, !$opts[:unusual], $opts[:archive], nil, labels + when "maildir" + Redwood::Maildir.new uri, nil, !$opts[:unusual], $opts[:archive], nil, labels + when "mbox" + Redwood::MBox::Loader.new uri, nil, !$opts[:unusual], $opts[:archive], nil, labels + when nil + Trollop::die "Sources must be specified with an URI" + else + Trollop::die "Unknown source type #{parsed_uri.scheme.inspect}" + end + say "Adding #{source}..." + Redwood::SourceManager.add_source source + end +ensure + index.save + index.unlock + Redwood::finish +end