function JSONRPCMethod(url,method) { if (arguments.length == 1) { var j = url.indexOf('#'); if (j == -1) throw "Usage: new JSONRPCMethod(\"http://site/json.cgi#method\");"; method = url.substr(j+1,url.length-(j+1)); url = url.substr(0, j); } if (method.indexOf('(') > -1) { method = method.substr(0, method.indexOf('(')); if (method == '') throw "Usage: new JSONRPCMethod(\"http://site/json.cgi#method\");"; } var m = { '\b': '\\b', '\t': '\\t', '\n': '\\n', '\f': '\\f', '\r': '\\r', '"' : '\\"', '\\': '\\\\' }; var s = { array: function (x) { var a = ['['], b, f, i, l = x.length, v; for (i = 0; i < l; i += 1) { v = x[i]; f = s[typeof v]; if (f) { v = f(v); if (typeof v == 'string') { if (b) a[a.length] = ','; a[a.length] = v; b = true; } } } a[a.length] = ']'; return a.join(''); }, 'boolean': function (x) { return String(x); }, 'null': function (x) { return "null"; }, number: function (x) { return isFinite(x) ? String(x) : 'null'; }, object: function (x) { if (x) { if (x instanceof Array || typeof x == 'array') { return s.array(x); } var a = ['{'], b, f, i, v; for (i in x) { v = x[i]; f = s[typeof v]; if (f) { v = f(v); if (typeof v == 'string') { if (b) a[a.length] = ','; a[a.length]=s.string(i); a[a.length]=':'; a[a.length]=v; b = true; } } } a[a.length] = '}'; return a.join(''); } return 'null'; }, string: function (x) { if (/["\\\x00-\x1f]/.test(x)) { x = x.replace(/([\x00-\x1f\\"])/g, function(a, b) { var c = m[b]; if (c) { return c; } c = b.charCodeAt(); return '\\u00' + Math.floor(c / 16).toString(16) + (c % 16).toString(16); }); } return '"' + x + '"'; } }; function parseJSON_slow(x) { var i = 0; function c_hex() { var c = x.substr(i, 1).toLowerCase(); i++; var j = '0123456789abcdef'.indexOf(c); if (j > -1) return j; throw "Invalid/unexpected hex character"; } function c_octal(n) { var c = x.substr(i, 1); i++; if ('01234567'.indexOf(c) > -1) { n *= 8; n += parseInt(c); } else { i--; return n; } c = x.substr(i, 1); i++; if ('01234567'.indexOf(c) > -1) { n *= 8; n += parseInt(c); } else { i--; } return n; } function c_backslash() { var c = x.substr(i, 1); i++; var n; if (c == "b") return "\b"; if (c == "r") return "\r"; if (c == "n") return "\n"; if (c == "t") return "\t"; if (c == "f") return "\f"; if (c == "a") return "\a"; if (c == 'u') { n = c_hex(); n *= 256; n += c_hex(); n *= 256; n += c_hex(); n *= 256; n += c_hex(); return String.fromCharCode(n); } else if (c == 'x') { n = c_hex(); n *= 256; n += c_hex(); return String.fromCharCode(n); } else if ('01234567'.indexOf(c) > -1) { n = c_octal(parseInt(c)); return String.fromCharCode(n); } return c; } function c_next() { if (i >= x.length) return false; var c = x.substr(i, 1); i++; while (' \r\t\n\f'.indexOf(c) > -1) { i++; if (i >= x.length) return false; c = x.substr(i, 1); } return c; } function p_bareword(c) { var s = [c]; while (i < x.length) { c = c_next(); if (":,([{\"'\\}])".indexOf(c) > -1) { i--; return s.join(''); } s[s.length] = c; } return s.join(''); } function p_string(q) { var s = []; while (i < x.length) { var c = x.substr(i, 1); i++; if (c == "\\") { c = c_backslash(); } else if (c == q) { return s.join(''); } s[s.length] = c; } throw "Syntax Error: Expected \" at end of string"; } function p_list(cl) { var a = []; var c = c_next(); if (c == cl) { return a; } i--; while (i < x.length) { var g = p_root(); a[a.length] = g; c = c_next(); if (c == cl) { return a; } if (c != ',') { throw "Syntax Error: Expected "+cl+" or , after list item"; } } throw "Syntax Error: Expected "+cl+" at end of list"; } function p_dict() { var a = {}; var c = c_next(); if (c == '}') return a; while (i < x.length) { var k, v; if (c == '"' || c == "'") { k = p_string(c); } else { k = p_bareword(c); } c = c_next(); if (c != ':' && c != ',') { throw "Syntax Error: Expected : at end of key"; } v = p_root(); a[k] = v; c = c_next(); if (c == '}') return a; if (c != ',') { throw "Syntax Error: Expected } or , after dict item"; } c = c_next(); } } function p_root() { var c = c_next(); if (c == '"' || c == "'") { return p_string(c); } if (c == '(') { c = p_list(')'); if (c.length > 0) return c[c.length-1]; return null; } if (c == '[') { return p_list(']'); } if (c == '{') { return p_dict(); } c = p_bareword(c); if ((parseInt(c)+'') == (c+'')) { return parseInt(c); } if ((parseFloat(c)+'') == (c+'')) { return parseFloat(c); } var g = c.toLowerCase(); if (g == 'true') return true; if (g == 'false') return false; if (g == 'undefined') return undefined; if (g == 'null') return null; if (g =='throw') { c = p_root(); throw c; } // invalid token? return c+''; } return p_root(); } function parseJSON(x) { var z; if (x=='') return z; try { eval('z='+x); } catch(e) { throw e; }; return z; } var f = function() { var i, a = []; a[0] = method; for (i = 0; i < arguments.length; i++) { a[i+1] = arguments[i]; } var ser = s.array(a); var x=false; /*@cc_on @*/ /*@if (@_jscript_version >= 5) try { x = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { x = new ActiveXObject("Microsoft.XMLHTTP"); } catch (E) { x = false; } } @end @*/ if (!x && typeof XMLHttpRequest!='undefined') { x = new XMLHttpRequest(); } var async = arguments.callee.onreturn||arguments.callee.onReturn||arguments.callee.onreply||arguments.callee.onReply||undefined; var errup = arguments.callee.onerror||arguments.callee.onError; if (!async) { if (errup) { try { x.open('POST', url, false); x.send(ser); if (x.readyState != 4) return false; if (x.status && x.status != 200) throw ''+x.status+' '+x.statusText; var txt = x.responseText+''; return parseJSON_slow(txt); } catch(e) { errup(e); }; return false; } x.open('POST', url, false); x.send(ser); if (x.readyState != 4) return false; if (x.status && x.status != 200) throw ''+x.status+' '+x.statusText; var txt = x.responseText+''; return parseJSON_slow(txt); } if (!errup) { errup = function(e) { window.alert(e); throw e; }; } (function(casync,cerrup) { try { x.open('POST', url, true); x.onreadystatechange = function() { try { if (x.readyState != 4) return; if (x.status && x.status != 200) throw ''+x.status+' '+x.statusText; var txt = x.responseText+''; x=null; casync(parseJSON(txt)); } catch(e) { x=null; cerrup(e); }; }; x.send(ser); } catch(e) { cerrup(e); }; })(async,errup); return true; }; f.parseJSON_fast = parseJSON; f.parseJSON_slow = parseJSON_slow; f.makeJSON_array = s['array']; f.full_url = url + '#' + method; f.toSource = function() { return '[JSONRPCMethod ' + this._full_url + ']'; }; f.toValue = f.toSource; f.valueOf = f.toSource; f.url = url; f.method = method; return f; } window['httpmail'] = {}; window['httpmail'].feed = {}; window['httpmail'].config = {}; window['httpmail'].async = {}; window['httpmail'].mailbox = {}; window['httpmail'].message = {}; window['httpmail'].calendar = {}; window['httpmail'].contacts = {}; window['httpmail'].calendar.subscribe = new JSONRPCMethod('backend.cgi', 'calendar.subscribe'); window['httpmail'].config.get = new JSONRPCMethod('backend.cgi', 'config.get'); window['httpmail'].expunge = new JSONRPCMethod('backend.cgi', 'expunge'); window['httpmail'].message.setFlags = new JSONRPCMethod('backend.cgi', 'message.setFlags'); window['httpmail'].mailbox.listingJAVA = new JSONRPCMethod('backend.cgi', 'mailbox.listingJAVA'); window['httpmail'].message.fetchTHUMBNAIL = new JSONRPCMethod('backend.cgi', 'message.fetchTHUMBNAIL'); window['httpmail'].contacts.update = new JSONRPCMethod('backend.cgi', 'contacts.update'); window['httpmail'].feed.unsubscribe = new JSONRPCMethod('backend.cgi', 'feed.unsubscribe'); window['httpmail'].message.forwardSet = new JSONRPCMethod('backend.cgi', 'message.forwardSet'); window['httpmail'].mailbox.remove = new JSONRPCMethod('backend.cgi', 'mailbox.remove'); window['httpmail'].message.fetchHTML = new JSONRPCMethod('backend.cgi', 'message.fetchHTML'); window['httpmail'].message.forward = new JSONRPCMethod('backend.cgi', 'message.forward'); window['httpmail'].message.fetch = new JSONRPCMethod('backend.cgi', 'message.fetch'); window['httpmail'].calendar.todo = new JSONRPCMethod('backend.cgi', 'calendar.todo'); window['httpmail'].message.fetchJAVA = new JSONRPCMethod('backend.cgi', 'message.fetchJAVA'); window['httpmail'].async.listen = new JSONRPCMethod('backend.cgi', 'async.listen'); window['httpmail'].config.setPassword = new JSONRPCMethod('backend.cgi', 'config.setPassword'); window['httpmail'].send = new JSONRPCMethod('backend.cgi', 'send'); window['httpmail'].spellcheck = new JSONRPCMethod('backend.cgi', 'spellcheck'); window['httpmail'].feed.burn = new JSONRPCMethod('backend.cgi', 'feed.burn'); window['httpmail'].mailbox.moveto = new JSONRPCMethod('backend.cgi', 'mailbox.moveto'); window['httpmail'].message.markspam = new JSONRPCMethod('backend.cgi', 'message.markspam'); window['httpmail'].message.structure = new JSONRPCMethod('backend.cgi', 'message.structure'); window['httpmail'].mailbox.ping = new JSONRPCMethod('backend.cgi', 'mailbox.ping'); window['httpmail'].contacts.list = new JSONRPCMethod('backend.cgi', 'contacts.list'); window['httpmail'].contacts.create = new JSONRPCMethod('backend.cgi', 'contacts.create'); window['httpmail'].message.fetchVCARD = new JSONRPCMethod('backend.cgi', 'message.fetchVCARD'); window['httpmail'].mailbox.summary = new JSONRPCMethod('backend.cgi', 'mailbox.summary'); window['httpmail'].async.unlisten = new JSONRPCMethod('backend.cgi', 'async.unlisten'); window['httpmail'].message.reply = new JSONRPCMethod('backend.cgi', 'message.reply'); window['httpmail'].mailbox.list = new JSONRPCMethod('backend.cgi', 'mailbox.list'); window['httpmail'].calendar.fetch = new JSONRPCMethod('backend.cgi', 'calendar.fetch'); window['httpmail'].mailbox.copyto = new JSONRPCMethod('backend.cgi', 'mailbox.copyto'); window['httpmail'].mailbox.create = new JSONRPCMethod('backend.cgi', 'mailbox.create'); window['httpmail'].config.set = new JSONRPCMethod('backend.cgi', 'config.set'); window['httpmail'].calendar.unsubscribe = new JSONRPCMethod('backend.cgi', 'calendar.unsubscribe'); window['httpmail'].mailbox.messages = new JSONRPCMethod('backend.cgi', 'mailbox.messages'); window['httpmail'].message.notspam = new JSONRPCMethod('backend.cgi', 'message.notspam'); window['httpmail'].feed.subscribe = new JSONRPCMethod('backend.cgi', 'feed.subscribe'); window['httpmail'].license = new JSONRPCMethod('backend.cgi', 'license'); window['httpmail'].calendar.file = new JSONRPCMethod('backend.cgi', 'calendar.file'); window['httpmail'].message.archive = new JSONRPCMethod('backend.cgi', 'message.archive'); window['httpmail'].mailbox.post = new JSONRPCMethod('backend.cgi', 'mailbox.post'); window['httpmail'].now = new JSONRPCMethod('backend.cgi', 'now'); window['httpmail'].message.remove = new JSONRPCMethod('backend.cgi', 'message.remove'); window['httpmail'].calendar.alarms = new JSONRPCMethod('backend.cgi', 'calendar.alarms'); window['httpmail'].message.resume = new JSONRPCMethod('backend.cgi', 'message.resume'); window['httpmail'].calendar.update = new JSONRPCMethod('backend.cgi', 'calendar.update');