def article_added(self, rawdog, config, article, now): """Handle new articles using the article_seen hook.""" mail_str = "" # Return immediately if nobody to send to if (not self.mailto): return True feed = rawdog.feeds[article.feed] if article.entry_info.has_key('title'): mail_str += "%s\n" % article.entry_info['title'] if article.entry_info.has_key('link'): mail_str += "%s\n\n" % article.entry_info['link'] # mail_str += ' [' + feed.get_html_link(config) + ']' #if article.entry_info.has_key('description'): # mail_str += "%s\n" % article.entry_info['description'] msg = MIMEText(encode_references(mail_str)) if article.entry_info.has_key('title'): msg['Subject'] = article.entry_info['title'] else: msg['Subject'] = "" msg['To'] = self.mailto msg['From'] = self.mailfrom SENDMAIL = "/usr/sbin/sendmail" # sendmail location import os p = os.popen("%s -t" % SENDMAIL, "w") p.write(msg.as_string()) sts = p.close() return True
def shutdown(self, rawdog, config): if (not self.mailto): return True if (self.mail_str == ''): return True msg = MIMEText(encode_references(self.mail_str + "\n\n.\n\n"), "html") msg['Subject'] = "rawdog" msg['To'] = self.mailto msg['From'] = self.mailfrom if (not msg['From'] or not msg['To']): return True # Experience says that 'sendmail' is the easiest/most reliable # way to send this mail out. YMMV, and it certainly isn't # portable. Leaving the previous version of the code in place. #smtp = smtplib.SMTP('localhost') #smtp.set_debuglevel(1) ##smtp.connect('smtp-host.net') ##smtp.connect('localhost') #smtp.sendmail(msg['From'], msg['To'], msg.as_string()) ##smtp.close() #smtp.quit() SENDMAIL = "/usr/sbin/sendmail" # sendmail location import os p = os.popen("%s -t" % SENDMAIL, "w") #p.write("To: " + msg['To'] + "\n") #p.write("Subject: rawdog cmdline\n") #p.write("\n") # blank line separating headers from body p.write(msg.as_string()) sts = p.close() #if sts != 0: # print "Sendmail exit status", sts return True
def safe_strftime(obj, format): """Call the strftime method on an object, and convert the result to ASCII-encoded HTML.""" u = unicode(obj.strftime(format), get_system_encoding()) return encode_references(u)