X-Git-Url: https://git.notmuchmail.org/git?a=blobdiff_plain;ds=inline;f=bin%2Fsup-add;h=e27a0ebf6ff446a9347d4fd8937653ab45b97db8;hb=beee5b381eb1d3e6b4541bacf039d62bf5914f29;hp=48949207ad48bdd4230e79d090213641715efeb0;hpb=ccdd089f46cf38f32fb1d36e2bf78daf7d589b15;p=sup diff --git a/bin/sup-add b/bin/sup-add old mode 100644 new mode 100755 index 4894920..e27a0eb --- a/bin/sup-add +++ b/bin/sup-add @@ -37,6 +37,7 @@ 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 @@ -76,37 +77,47 @@ end $terminal.wrap_at = :auto Redwood::start -index = Redwood::Index.new -index.load +index = Redwood::Index.init -ARGV.each do |uri| - if !$opts[:force_new] && index.source_for(uri) - say "Already know about #{uri}; skipping." - next - end +index.lock_interactively or exit + +begin + Redwood::SourceManager.load_sources - 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, index.sources - Redwood::MBox::SSHLoader.new uri, username, password, nil, !$opts[:unusual], $opts[:archive] - when "imap", "imaps" - username, password = get_login_info uri, index.sources - Redwood::IMAP.new uri, username, password, nil, !$opts[:unusual], $opts[:archive] - when "maildir" - Redwood::Maildir.new uri, nil, !$opts[:unusual], $opts[:archive] - when "mbox" - Redwood::MBox::Loader.new uri, nil, !$opts[:unusual], $opts[:archive] - else - Trollop::die "Unknown source type #{parsed_uri.scheme.inspect}" + 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 -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