aboutsummaryrefslogtreecommitdiffstats
path: root/puke-import
blob: 1a7c50005bca22fabcea5887dc5ef0561beda3e1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/usr/bin/env ruby
require "uri"
require "net/http"

# usage: puke-import URI <mboxrd files...>
#    or: cat mboxrd | puke-import URI
#
# URI is the url for importing an message.
# E.g. 'http://localhost:8080/new/secret-string'

uri = URI.parse(ARGV.shift)
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = uri.scheme == "https"
http.start {
  ARGF.binmode
  while true
    io = ARGF.to_io
    name = File === io ? io.path : io.inspect
    print "Importing #{name}... "
    req = http.post(uri.path, io.read,
                    "Content-Type" => "application/octet-stream")
    puts "done; mid=#{req.body}"
    ARGF.skip
    break if ARGF.to_io == io
  end
}