def start(self): SHOULD_DISPLAY = 1 if self._israwpage: SHOULD_DISPLAY = 0 ncgi = self.ncgi if self.readDefaultHDF: try: if not self.pagename is None: ncgi.hdf.readFile("%s.hdf" % self.pagename) except: log("Error reading HDF file: %s.hdf" % (self.pagename)) DISPLAY_ERROR = 0 ERROR_MESSAGE = "" # call page main function! try: self.main() except DisplayDone: SHOULD_DISPLAY = 0 except Redirected: # catch redirect exceptions SHOULD_DISPLAY = 0 except DisplayError, num: ncgi.hdf.setValue("Query.error", str(num)) if self._error_template: ncgi.hdf.setValue("Content", self._error_template) else: DISPLAY_ERROR = 1
def index_mbox (fp, name, mboxpath, pos=0): def raw_message(fp): return fp.read() mbox = mymailbox.UberUnixMailbox(fp, factory=raw_message) mbox.seekp = pos listpath = name mdb = message_db.MessageDB(listpath) mdb.createTables() count = 1 while 1: msg = mbox.next() if not msg: break try: mdb.insertMessage(msg) except KeyboardInterrupt: sys.exit(1) except: handle_error.handleException("Couldn't handle msg ending at: %s" % (fp.tell())) if (count % 8000) == 0: log("flushing... (%s)" % count) mdb.flush() log("done.") count = count + 1 mdb.flush() ## write the new position in the mbox #pos = fp.tell() pos = os.stat(mboxpath).st_size mboxpos_fn = os.path.join(listpath, "mbox.pos") open(mboxpos_fn, "w").write(str(pos))
def display_attachment(self): self.pagename = "attach" if len(self.path_info) > 3: try: num = int(self.path_info[2]) except ValueError: num = -1 else: raise Exception("invalid attachment URL") attachname = urllib.unquote(string.join(self.path_info[3:],"/")) log("attach name: %s" % attachname) meta = self.mdb.message(num, full=1) rm = RenderMessage(rawmsg=meta.msg_data, tz=self.tz) ct,body,name = rm.part_content(attachname) if ct and body: self.output("Content-Type: %s\r\n\r\n" % ct) self.output(body) else: log("didn't find it") raise CSPage.DisplayDone, "Attachment displayed"
def Action_SetPrefs(self): q_tz = self.ncgi.hdf.getValue("Query.timezone", self.tz) if q_tz == "default": self.ncgi.cookieClear("TZ") else: self.ncgi.cookieSet("TZ", q_tz, persist=1) q_browse_style = self.ncgi.hdf.getValue("Query.browse_style", self.browse_type) if q_browse_style not in ["frame", "iframe", "noframes"]: q_browse_style = "noframes" q_multi_msg = self.ncgi.hdf.getIntValue("Query.multi_msg", 0) self.ncgi.cookieSet("DPrefs", "v=1&browse=%s&multi=%d" % (q_browse_style, q_multi_msg), persist=1) wr_key = self.ncgi.hdf.getValue("Query.whichread_key", "") if wr_key: wr_key = string.replace(wr_key," ","_") # escape space self.ncgi.hdf.setValue("Cookie.WRID",wr_key) self.ncgi.cookieSet("WRID",wr_key,persist=1) # clear the whichread cookies obj = self.ncgi.hdf.getObj("Cookie.WR") if obj: obj = obj.child() while obj: cookiename = "WR.%s" % obj.name() log("clear cookie: %s" % cookiename) self.ncgi.cookieClear(cookiename) obj = obj.next() # end and redirect uri_root = self.ncgi.hdf.getValue("CGI.URIRoot", "/") self.redirectUri("%s%s" % (uri_root, self.listname))
def search_author(self, email): srch_idx = self.openSearchIndex('r') log("search %s" % email) results = srch_idx.search("author=(%s)" % email.lower()) log(str(results)) msgs = [] for num in results: msgs.append(self.message(int(num), full=1)) return msgs
def dumpDebug(self, etime): log("dumpDebug") print "<HR>\n" if etime: print "Execution Time: %5.3f<BR><HR>" % (etime) print '<table align=center width=90% style="font-size:10pt">' bgcolor = "#eeeeee" import math for p in profiler.PROFILER_DATA: if bgcolor == "#dddddd": bgcolor = "#eeeeee" else: bgcolor = "#dddddd" print "<tr bgcolor=%s><td NOWRAP>%02d:%04d<td>%5.3fs<td>%s<td>%s</tr>" % (bgcolor, math.floor(p.when),(p.when - math.floor(p.when)) * 10000, p.length, p.klass, p.what) print "</table>"
def check_visit_cookie(self): ncgi = self.ncgi hdf = self.ncgi.hdf visit_cur = hdf.getValue("Cookie.%s.visit_cur" % self.listname,"") visit_last = hdf.getValue("Cookie.%s.visit_last" % self.listname,"") max_doc, max_thread = self.mdb.counts() new_cookie = "%s:%s:%s" % (int(time.time()),max_doc,max_thread) if not visit_cur: ncgi.cookieSet("%s.visit_cur" % self.listname,new_cookie,persist=1) else: log("%s.visit_cur: %s" % (self.listname,visit_cur)) try: a_time,max_mnum,max_tid = string.split(visit_cur,":") if (time.time() - int(a_time)) > VISIT_DURATION: ncgi.cookieSet("%s.visit_last" % self.listname,visit_cur) ncgi.cookieSet("%s.visit_cur" % self.listname,new_cookie,persist=1) hdf.setValue("Cookie.%s.visit_last" % self.listname,visit_cur) hdf.setValue("Cookie.%s.visit_cur" % self.listname,new_cookie) except: ncgi.cookieSet("%s.visit_cur" % self.listname,new_cookie,persist=1)
def display_top_authors(self): self.pagename = "top_authors" q_date = self.ncgi.hdf.getValue("Query.date", "total") q_start_date = self.ncgi.hdf.getValue("Query.start_date","") authors = self.mdb.openAuthorIndex('r') data = authors.get_top(q_date) COLS_PER_PAGE = 8 n = 0 first_month = None last_month = None # export the info for (count, email) in data[:20]: authorRow = authors.get(email) bymonth = authorRow.getByMonth() self.ncgi.hdf.setValue("CGI.TopAuthors.%d.email" % n, authorRow.email) self.ncgi.hdf.setValue("CGI.TopAuthors.%d.name" % n, authorRow.name) if 1: months = bymonth.keys() months.remove('total') months.sort() months.reverse() if not first_month or first_month > months[-1]: first_month = months[-1] if not last_month or last_month < months[0]: last_month = months[0] for month in months: self.ncgi.hdf.setValue("CGI.TopAuthors.%d.%s" % (n, month), str(bymonth[month])) self.ncgi.hdf.setValue("CGI.TopAuthors.%d.total" % (n), str(bymonth.get('total', 0))) n += 1 if q_start_date: last_month = q_start_date # now, export information about what months we're displaying if first_month: self.ncgi.hdf.setValue("CGI.Months.0", "total") if q_date == "total": self.ncgi.hdf.setValue("CGI.Months.0.hilight", "1") n = 1 (fyear, fmon) = first_month.split('-') (lyear, lmon) = last_month.split('-') year = int(lyear) mon = int(lmon) fyear = int(fyear) fmon = int(fmon) bym = self.mdb.openByMonth() # compute previous month for "<< next" nav for a_col in range(1,COLS_PER_PAGE): next_mon = mon + a_col next_year = year while next_mon > 12: next_mon = next_mon - 12 next_year = next_year + 1 next_date = "%s-%02d" % (next_year,next_mon) bym_firstnum,bym_count = bym.get(next_date) if bym_count > 0: self.ncgi.hdf.setValue("CGI.MonthPage.NextDate",next_date) while n < COLS_PER_PAGE: date = '%s-%02d' % (year, mon) self.ncgi.hdf.setValue("CGI.Months.%d" % n, date) self.ncgi.hdf.setValue("CGI.Months.%d.year" % n, str(year)) self.ncgi.hdf.setValue("CGI.Months.%d.month" % n, str(mon)) if date == q_date: self.ncgi.hdf.setValue("CGI.Months.%d.hilight" % n, date) n += 1 mon -= 1 if mon == 0: mon = 12 year -= 1 if year < fyear: break if year == fyear and mon < fmon: break # compute "prev >>" nav from vars falling down prev_date = "%s-%02d" % (year,mon) log("*** %s = %s" % (prev_date,bymonth.get(prev_date,0))) bym_firstnum,bym_count = bym.get(prev_date) if bym_count > 0: self.ncgi.hdf.setValue("CGI.MonthPage.PrevDate",prev_date) self.ncgi.hdf.setValue("CGI.TopAuthors", str(n))
def export_msg_data(self, msg, prefix, hdf): log("%d" % msg.doc_id) rm = RenderMessage(rawmsg = msg.msg_data, tz=self.tz) uri_root = self.ncgi.hdf.getValue("CGI.URIRoot", "/") attach_url_base = "%s%s/attach/%s/%%s" % (uri_root, self.listname, msg.doc_id) rm.export_message(prefix, hdf, attach_str=attach_url_base)
def output(self, str): try: self.context.stdout.write(str) except IOError, reason: log("IOError: %s" % (repr(reason))) raise DisplayDone
if self.debugEnabled: p.end() # debug output if debug_output: self.dumpDebug(etime) print "<HR>\n" print "<PRE>" print neo_cgi.htmlEscape(ncgi.hdf.dump()) print "</PRE>" script_name = ncgi.hdf.getValue("CGI.ScriptName","") if script_name: script_name = string.split(script_name,"/")[-1] log ("[%s] etime/dtime: %5.3f/%5.3f %s (%s)" % (self.domain, etime, time.time() - etime - self.page_start_time, script_name, self.pagename)) # a protected output function to catch the output errors that occur when # the server is either restarted or the user pushes the stop button on the # browser def output(self, str): try: self.context.stdout.write(str) except IOError, reason: log("IOError: %s" % (repr(reason))) raise DisplayDone def allQuery (self, s): l = [] if self.ncgi.hdf.getValue ("Query.%s.0" % s, ""):