Module: Mailmate::CLI::Open Private
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
‘mmopen` — open one MailMate message in the MailMate UI by handing the `mid:` URL to macOS’s ‘open`. Read-side (doesn’t change message state), but activates MailMate’s window and brings it forward.
Accepts any of the six id forms ‘EmlLookup.resolve_id` understands —eml-id, RFC Message-ID with or without angle brackets, message://… URL, or mid:… URL.
Instance Method Summary collapse
- #parse_options(argv) ⇒ Object private
- #run(argv) ⇒ Object private
- #usage_error(msg) ⇒ Object private
Instance Method Details
#parse_options(argv) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/mailmate/cli/open.rb', line 54 def (argv) opts = { print_only: false, background: false } OptionParser.new do |o| o. = "Usage: mmopen <id> [--print] [--background|-g]" o.separator "" o.separator "Open a MailMate message in MailMate's UI. <id> can be a local" o.separator "eml-id, an RFC Message-ID (with or without angle brackets), or" o.separator "a message://… or mid:… URL." o.on("--print", "Print the mid: URL instead of opening it (for piping)") { opts[:print_only] = true } o.on("-g", "--background", "Open without bringing MailMate to the foreground") { opts[:background] = true } end.parse!(argv) opts end |
#run(argv) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/mailmate/cli/open.rb', line 18 def run(argv) opts = (argv) input = argv.first return usage_error("missing <id>") if input.nil? || input.empty? eml_id = Mailmate::EmlLookup.resolve_id(input) if eml_id.nil? || eml_id.zero? warn "mmopen: not found: #{input.inspect} (couldn't resolve as eml-id or Message-ID)" return 1 end path = Mailmate::EmlLookup.path_for(eml_id) unless path warn "mmopen: not found: #{eml_id}.eml" return 1 end = Mailmate::HeaderReader.(path) unless warn "mmopen: could not find Message-ID in #{path}" return 1 end url = Mailmate::MidUrl.for() if opts[:print_only] $stdout.puts url return 0 end cmd = ["/usr/bin/open"] cmd << "-g" if opts[:background] cmd << url system(*cmd) $?.exitstatus end |
#usage_error(msg) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
68 69 70 71 72 |
# File 'lib/mailmate/cli/open.rb', line 68 def usage_error(msg) warn "mmopen: #{msg}" warn "Usage: mmopen <id> [--print] [--background|-g]" 2 end |