def __init__(self, source=None, raise_exception=True): self.valid = False try: if source == None: self.msg = email.Message.Message() self.msg["Date"] = email.Utils.formatdate() self.msg["From"] = "<*****@*****.**> Wilber Gimp" self.msg["Message-Id"] = "<" + time.strftime("%Y%m%d%H%M%S-") + str(os.getpid()) + "@news.gimp.org>" self.msg["Reply-To"] = "" self.msg["Subject"] = "(none)" self.msg[news.editor_header] = "" self.msg[news.image_header] = "--none--" self.msg.set_payload("") self.msg.epilogue = "" self.valid = True elif str(source.__class__) == 'cgi.FieldStorage': self.msg = email.Message.Message() self.msg["Date"] = email.Utils.formatdate(calendar.timegm(email.Utils.parsedate(xhtml.unescape(source["date"].value)))) self.msg["From"] = xhtml.unescape(source["from"].value) self.msg["Message-Id"] = xhtml.unescape(source["message-id"].value) self.msg["Reply-To"] = "" self.msg["Subject"] = xhtml.unescape(source["subject"].value) self.msg[news.editor_header] = xhtml.unescape(source["editor"].value) self.msg[news.image_header] = xhtml.unescape(source["image"].value) self.msg.set_payload(source["body"].value) self.msg.epilogue = "" self.valid = True elif str(source.__class__) == "<type 'str'>": if source.endswith('news-blotter') or source.endswith('news.rdf'): self.valid = False else: fd = open(source, "r") self.msg = email.message_from_file(fd) fd.close() self.valid = True elif str(source.__class__) == 'email.Message.Message': self.msg = source self.valid = True pass else: self.valid = False pass if hasattr(self, 'msg'): if not self.msg.has_key(news.image_header): self.msg[news.image_header] = "" if not self.msg.has_key(news.editor_header): self.msg[news.editor_header] = "" pass pass except: self.valid = False if raise_exception: raise ValueError pass return (None)
def as_rdf(self): http_host = config.default_http_host if os.environ.has_key("HTTP_HOST"): http_host = os.environ["HTTP_HOST"] pass url = "http://" + http_host date = email.Utils.formatdate(calendar.timegm(email.Utils.parsedate(xhtml.unescape(self["date"])))) s = rdf.item(rdf.title(rdf.quote(self["subject"])) + rdf.description(rdf.quote(xhtml.absolutize(self["body"], url))) + "\n" + rdf.link(url) + "\n" + rdf.pubDate(rdf.quote(date))) return (s)
def as_news_item(self): # As a line in the blotter iso_date = time.strftime(config.datetime_format, time.gmtime(calendar.timegm(email.Utils.parsedate(xhtml.unescape(self["date"]))))) s = str(xhtml.comment("$Id$")) + str(xhtml.span(xhtml.quote(self["subject"]), {"class" : "newstitle"}) + xhtml.span(xhtml.quote(iso_date), {"class" : "newsdate"})) s = xhtml.h1(s + " ", {"class" : "newsheading"}) img = "" if icon_by_name(self["image"]) != "": img = xhtml.image({"src" : config.icon_dir + icon_by_name(self["image"])}) pass s += str(xhtml.div(img + as_para(self["body"]), {"class" : "news"})) return (s)
def main(): wgo_news.header() form = cgi.FieldStorage() if not (form.has_key("message-id") and form.has_key("queue")): wgo_news.footer(wgo.error("Malformed Request")) return (1) queue = form["queue"].value if queue in ["pending", wgo_news.config.pending_queue]: this_queue = wgo_news.config.pending_queue other_queue = wgo_news.config.current_queue elif queue in ["current", wgo_news.config.current_queue]: this_queue = wgo_news.config.current_queue other_queue = wgo_news.config.pending_queue elif queue in ["archive", wgo_news.config.archive_queue]: this_queue = wgo_news.config.archive_queue other_queue = wgo_news.config.archive_queue else: wgo_news.footer(wgo.error("Malformed request")) return (1) message_id = xhtml.unescape(form["message-id"].value) try: m = wgo_news.news(wgo_queue.message_path(this_queue, message_id)) except: m = wgo_news.news() m["message-id"] = message_id m["date"] = rfc822.formatdate() pass if os.environ.has_key("REMOTE_USER"): editor = os.environ["REMOTE_USER"] else: editor = "*****@*****.**" pass html_news_edit(this_queue, other_queue, m, editor) wgo_news.footer() return (0)
action = string.lower(form["action"].value) pass if queue == "" or action == "": print wgo_news.error("Malformed request") wgo_news.footer() sys.exit(1) pass print xhtml.table.init({"class" : "batch"}) print xhtml.table.row(xhtml.table.header("Action") + xhtml.table.header("Message-Id") + xhtml.table.header("Status")) for key in form.keys(): if not key in ["queue", "action"]: message_id = xhtml.unescape(key) print xhtml.table.row.init() print xhtml.table.cell(action) print xhtml.table.cell(xhtml.quote(message_id)) if action == "save": status = 0 elif action in ["approve", "current"]: try: os.rename(wgo_queue.message_path(queue, message_id), wgo_queue.message_path(wgo_news.config.current_queue, message_id)) status = 0 except OSError, e: status = e.strerror pass pass elif action == "archive":
def main(): form = cgi.FieldStorage() #wgo.config.debug = True if wgo.config.debug: xhtml.print_form(form) if not (form.has_key("message-id") and form.has_key("action") and form.has_key("queue")) and not (form.has_key("subject") and form.has_key("body")): wgo_news.header() wgo_news.footer(wgo.error("Malformed http request.")) return (-1) action = string.lower(xhtml.unescape(form["action"].value)) queue = xhtml.unescape(form["queue"].value) if queue in ["pending", wgo_news.config.pending_queue]: queue = wgo_news.config.pending_queue elif queue in ["current", wgo_news.config.current_queue]: queue = wgo_news.config.current_queue elif queue in ["archive", wgo_news.config.archive_queue]: queue = wgo_news.config.archive_queue else: action = "" queue = "" pass try: news = wgo_news.news(form) except: wgo_news.header() wgo_news.footer(wgo.error("The news article is malformed. Check the date, it should be <i>day month year hour:minute:seconds</i> GMT Perhaps it is missing a subject line, or it has no body. ")) return (-1) if action == "save": news.to_queue(queue) link = xhtml.hyperlink("Continue", { "href" : "news-edit.cgi?message-id=%s&queue=%s" % (news["message-id"], queue)}) status = "success" goto = ["Location: news-edit.cgi?message-id=%s&queue=%s" % (xhtml.escape(news["message-id"]), queue)] elif action == "approve": news.to_queue(wgo_news.config.current_queue) if os.path.exists(wgo_queue.message_path(queue, news["message-id"])): os.remove(wgo_queue.message_path(queue, news["message-id"])) pass link = xhtml.hyperlink("Continue", { "href" : "news-index.cgi?%s" % (queue)}) status = "success" goto = ["Location: news-index.cgi?%s" % (queue)] elif action == "disapprove": news.to_queue(wgo_news.config.pending_queue) if os.path.exists(wgo_queue.message_path(queue, news["message-id"])): os.remove(wgo_queue.message_path(queue, news["message-id"])) pass link = xhtml.hyperlink("Continue", {"href" : "news-index.cgi?%s" % (queue)}) status = "success" goto = ["Location: news-index.cgi?%s" % (queue)] elif action == "archive": news.to_queue(wgo_news.config.archive_queue) if os.path.exists(wgo_queue.message_path(queue, news["message-id"])): os.remove(wgo_queue.message_path(queue, news["message-id"])) pass link = xhtml.hyperlink("Continue", {"href" : "news-index.cgi?%s" % (queue)}) status = "success" goto = ["Location: news-index.cgi?%s" % (queue)] elif action == "delete": if os.path.exists(wgo_queue.message_path(queue, news["message-id"])): os.remove(wgo_queue.message_path(queue, news["message-id"])) pass link = xhtml.hyperlink("Continue", {"href" : "news-index.cgi?%s" % (queue)}) status = "success" goto = ["Location: news-index.cgi?%s" % (queue)] else: link = xhtml.hyperlink("Restart", {"href" : "index.html"}) queue = "" status = "failed" pass if status == "success": print goto[0] print else: wgo_news.header() wgo_news.footer(wgo.error(string.capitalize(action) + " " + string.capitalize(status))) pass return (0)