Excerpts from Austin Ziegler's mail of 18 Jul 2005 (EDT):
> Use Net::SMTP.
Attached is a patch that adds email notification for new comments via
Net::SMTP. It Works For Me (tm) but that's all I can guarantee at this
point.
Overall I don't think I'll commit this unless people really want it.
It's very ugly. Maybe a better approach would be to have some kind of
simple hook system on Storage#save_attached. Then I could move this off
to another file rather than cluttering facets/comments.rb. What do yinz
think?
Either way I think Frederick's idea of an RSS feed is great and I will
be doing that as well.
So comments, as always, are very welcome. In particular, if there's a
better way to store parameters from hobix.yaml than the filthy pile of
class variables I use now, I would love to hear about it. I ain't no
Ruby expert. And if I should restructure it as above, please tell me.
Usage:
- hobix/comments:
email-notifications-to: <you email address>
smtp-server: <smtp server>
You can also optionally specify:
smtp-port: <25 by default>
hostname: <(what to report to the SMTP server during the HELO)
Socket::gethostname by default. I believe there is an RFC
that requires that SMTP servers don't reject based on this
field, but who knows in this day and age of spam.>
email-notifications-from: <"hobix-comments-noreply" by default>
--
William <[EMAIL PROTECTED]>
Index: lib/hobix/comments.rb
===================================================================
RCS file: /var/cvs/hobix/hobix/lib/hobix/comments.rb,v
retrieving revision 1.2
diff -u -r1.2 comments.rb
--- lib/hobix/comments.rb 24 Jul 2005 15:37:06 -0000 1.2
+++ lib/hobix/comments.rb 25 Jul 2005 23:25:16 -0000
@@ -14,9 +14,44 @@
# $Id: comments.rb,v 1.2 2005/07/24 15:37:06 wmorgan Exp $
#++
+require 'net/smtp'
+require 'socket'
require 'hobix/facets/comments'
module Hobix
+
+## we just keep parameters from hobix.yaml here
+class CommentPlugin < BasePlugin
+ def parse_address( s, hostname )
+ case s
+ when /^(.*)\s+<(.*?)>$/
+ short = $2
+ short += "@#{ hostname }" unless short =~ /@/
+ full = s
+ when /@/
+ short = full = s
+ else
+ short = full = "#{ s [EMAIL PROTECTED] hostname }"
+ end
+ [short, full]
+ end
+
+ def initialize( weblog, params = {} )
+ if params["email-notifications-to"]
+ @@server = params["smtp-server"] or raise %{the comment plugin
needs a "smtp-server" parameter if email notifications are turned on.}
+ @@port = params["smtp-port"] || 25
+ @@hostname = params["hostname"] || Socket::gethostname
+ @@from, @@from_full = parse_address(
params["email-notifications-from"] || "hobix-comments-noreply", @@hostname )
+ @@to, @@to_full = parse_address( params["email-notifications-to"],
@@hostname )
+ end
+ end
+ [:server, :port, :hostname, :from, :from_full, :to, :to_full].each do |a|
+ instance_eval "def #{ a }; @@#{ a }; end"
+ end
+
+ def self.email_notification?; !@@to.nil?; end
+end
+
module Out
class Quick
append_def :head_tags_erb, %{
Index: lib/hobix/facets/comments.rb
===================================================================
RCS file: /var/cvs/hobix/hobix/lib/hobix/facets/comments.rb,v
retrieving revision 1.3
diff -u -r1.3 comments.rb
--- lib/hobix/facets/comments.rb 24 Jul 2005 01:10:34 -0000 1.3
+++ lib/hobix/facets/comments.rb 25 Jul 2005 23:25:16 -0000
@@ -59,6 +59,29 @@
@weblog.storage.save_attached( entry_id, "comments", comments )
@weblog.regenerate :update
+ if CommentPlugin.email_notification?
+ Thread.new do
+ now = Time.now
+ body = <<END_OF_MESSAGE
+From: #{ CommentPlugin.from_full }
+To: #{ CommentPlugin.to_full }
+Subject: hobix comment from #{ comment.author }
+Date: #{ now.to_s }
+Message-Id: <hobix-comments-#{ now.to_i }-#{ now.usec [EMAIL PROTECTED]
CommentPlugin.hostname }>
+
+#{ comment.author } posted a comment to #{ entry_id }:
+
+#{ comment.content }
+END_OF_MESSAGE
+ Net::SMTP.start(CommentPlugin.server,
CommentPlugin.port,
+ CommentPlugin.hostname) do |smtp|
+ smtp.send_message body,
+ CommentPlugin.from,
+ CommentPlugin.to
+ end
+ end
+ end
+
# Redirect
link = @weblog.output_entry_map[entry_id]
app.setup_redirection( 302, link[:page].link )
_______________________________________________
Hobix-is-the-way mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/hobix-is-the-way