Sat, 11 Aug 2012 09:25:11 +0200
clix.archive: Print a newline if reading a line fails (the user pressed ^D)
local bare_jid = require"util.jid".bare; local parse_datetime = require"util.datetime".parse; return function (opts, arg) if opts.short_help then print("Fetch archived messages"); return; end if opts.start then opts.start = parse_datetime(opts.start); end if opts["end"] then opts["end"] = parse_datetime(opts["end"]); end local selfjid; local function print_message(i) -- TODO Roster lookup local m = i.message; local a = m.attr; if i.stamp then print(os.date(nil, i.stamp)); end if a.to and bare_jid(a.to) ~= selfjid then print("To ".. bare_jid(a.to)); end if a.from and bare_jid(a.from) ~= selfjid then print("From ".. bare_jid(a.from)); end print(m:get_child_text"body"); print""; end local function on_connect(conn) if opts.debug then conn:hook("stanza-out", print); conn:hook("stanza", print); end selfjid = bare_jid(conn.jid); local function handle_results(ok, result) for i=1,#result do print_message(result[i]); end if result.last then local fetch_next = opts.everything; if opts.interactive and not fetch_next then io.stderr:write "--More--" fetch_next = io.read"*l" or print(); end if fetch_next then opts.after = result.last; conn:query_archive(opts.to, opts, handle_results); return else conn:info("Next page: --after=%s", result.last); end end conn:close(); end conn:add_plugin"archive"; -- TODO conn:add_plugin"roster"; -- c.roster:fetch(function() conn:query_archive(opts.to, opts, handle_results); end clix_connect(opts, on_connect); end