def create_msg(rq_raw, u): ''' create msg from user form ''' rq = check_check(rq_raw) date = str(gts()) txt = rq.txt if rq.pic: for n in rq.pic.split(): txt += '\n\n@image: %s' % n o = mydict(txt=txt, title=rq.title, date=date, ea=rq.ea, who=u.uname, addr=u.uaddr, to=rq.to) if rq.repto: o.repto = rq.repto if rq.tags and not rq.topicid: o.tags = mk_tags(rq.tags) blob = fo.obj_to_file(o, 60).encode('utf-8') msgid = hsh(blob) o.topicid = rq.topicid or msgid o = msghook.hook(o, True) blob = fo.obj_to_file(o).encode('utf-8') write_msg(o, msgid, blob, date, True) return msgid
def savemsg(mo): s = _out(mo).encode('utf-8') h = sx.hsh(s) if len(s) < 65536: open('m/%s' % h, 'wb').write(s) open('e/%s' % mo.echoarea, 'ab').write(h + '\n') return h
def mkmsg(obj, rh=None): if not flt.echo_flt(obj.echoarea): return if rh and not flt.msg_flt(rh): return s = _out(obj).encode('utf-8') h = rh or sx.hsh(s) if len(s) < 65536: open('msg/%s' % h, 'wb').write(s) open('echo/%s' % obj.echoarea, 'ab').write(h + '\n') return h
def mkmsg(obj,rh=None): if not flt.echo_flt(obj.echoarea): return if rh and not flt.msg_flt(rh): return s = _out(obj).encode('utf-8') h = rh or sx.hsh(s) if len(s) < 65536: open('msg/%s' % h,'wb').write(s) open('echo/%s' % obj.echoarea,'ab').write(h + '\n') return h
def write_msg(o,msgid,blob,date,newflag): wf('data/m/%s' % msgid , blob) af('data/e/%s' % o.ea, '%s\n' % msgid) af('data/m.accepted', '%s %s\n' % (msgid,date)) wf('data/nuser/%s' % hsh(o.who.encode('utf-8')), o.who.encode('utf-8')) af('data/carbon/_%s' % hsh(o.who.encode('utf-8')), '%s\n' % msgid) af('data/carbon/%s' % hsh(o.to.encode('utf-8')), '%s\n' % msgid) if msgid != o.topicid: wf('data/topic/%s.updated' % o.topicid, '%s\n%s' % (str(o.date) or date,o.who.encode('utf-8'))) af('data/topic/%s' % o.topicid, '%s\n' % msgid) else: wf('data/topic/%s.updated' % msgid, '%s\n%s' % (str(o.date) or date,o.who.encode('utf-8'))) af('data/topic.list','%s\n' % msgid) af('data/et/%s' % o.ea, '%s\n' % msgid) wf('data/topic/%s' % msgid, u'%s\n%s\n%s\n%s\n%s\n%s\n' % (o.date,o.title,o.ea,o.who,o.addr,msgid),True) if o.tags: for n in o.tags.split(','): wf('data/ntag/%s' % hsh(n), b64d(n)) af('data/tags/%s' % hsh(n), '%s\n' % msgid)