Exemplo n.º 1
0
    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"
Exemplo n.º 2
0
    def display_search(self):
        RESULTS_PER_PAGE = 10

        self.pagename = "search"

        query = self.ncgi.hdf.getValue("Query.query", "")
        self.ncgi.hdf.setValue("CGI.query_url", neo_cgi.urlEscape(query))
        q_page = self.ncgi.hdf.getIntValue("Query.page", 1)
        start = (q_page - 1) * RESULTS_PER_PAGE
        if start < 0: start = 0
        if query:
            search_t = time.time()
            total, msgs = self.mdb.search(query, start, RESULTS_PER_PAGE)
            if total == 0:
                self.ncgi.hdf.setValue("CGI.SearchNoResults", "1")
            search_t = time.time() - search_t
            self.ncgi.hdf.setValue("CGI.SearchTime", "%5.2f" % search_t)
            self.ncgi.hdf.setValue("CGI.SearchStart", str(start+1))
            end = start+RESULTS_PER_PAGE
            if end > total:
                end = total
            self.ncgi.hdf.setValue("CGI.SearchEnd", str(end))
            self.ncgi.hdf.setValue("CGI.SearchTotal", str(total))
            pages = math.ceil(total*1.0/RESULTS_PER_PAGE)
            page = (start+1)/RESULTS_PER_PAGE + 1
            if pages > 20:
                # If we have more than 20 pages, only show the 20 around
                # the page we're looking at
                if page < 20:
                    self.ncgi.hdf.setValue("CGI.SearchPageStart", "1")
                    self.ncgi.hdf.setValue("CGI.SearchPageEnd", "20")
                elif page+10 > pages:
                    self.ncgi.hdf.setValue("CGI.SearchPageStart", str(pages-20))
                    self.ncgi.hdf.setValue("CGI.SearchPageEnd", str(pages))
                else:
                    self.ncgi.hdf.setValue("CGI.SearchPageStart", str(page-10))
                    self.ncgi.hdf.setValue("CGI.SearchPageEnd", str(page+10))
            else:
                self.ncgi.hdf.setValue("CGI.SearchPageStart", "1")
                self.ncgi.hdf.setValue("CGI.SearchPageEnd", str(pages))

            self.ncgi.hdf.setValue("CGI.SearchPages", str(pages))
            self.ncgi.hdf.setValue("CGI.SearchPage", str(page))

            n = 0
            for meta in msgs:
                meta.hdfExport("CGI.Matches.%d" % n, self.ncgi.hdf, tz=self.tz)
                count = self.mdb.thread_count(meta.thread_id)
                self.ncgi.hdf.setValue("CGI.Matches.%d.thread_count" % n, str(count))
                rm = RenderMessage(rawmsg = meta.msg_data, tz=self.tz)
                text = rm.as_text()
                snipper = search_help.Snippet()
                snippet = snipper.snippet(query, text)
                self.ncgi.hdf.setValue("CGI.Matches.%d.Snippet" % n, snippet)
                n = n + 1
Exemplo n.º 3
0
 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)