soc.2009.transport: 48fd97bf: notify_email handler

hanzz at soc.pidgin.im hanzz at soc.pidgin.im
Mon Jun 15 02:55:35 EDT 2009


-----------------------------------------------------------------
Revision: 48fd97bf756120abeb60abd506ab732b1fa43fd3
Ancestor: 7a5435990412da3a4bdcc872e3d7c33d0c302fd9
Author: hanzz at soc.pidgin.im
Date: 2009-06-15T06:51:42
Branch: im.pidgin.soc.2009.transport
URL: http://d.pidgin.im/viewmtn/revision/info/48fd97bf756120abeb60abd506ab732b1fa43fd3

Modified files:
        main.cpp main.h protocols/abstractprotocol.h
        protocols/facebook.h

ChangeLog: 

notify_email handler

-------------- next part --------------
============================================================
--- main.cpp	471c67559846e445ddde8388461651aa0f1e41f7
+++ main.cpp	98168ba4748690fcafc45547e2886a676e045341
@@ -350,6 +350,12 @@ static void * notify_user_info(PurpleCon
 	return NULL;
 }
 
+static void * notifyEmail(PurpleConnection *gc, const char *subject, const char *from, const char *to, const char *url)
+{
+	GlooxMessageHandler::instance()->notifyEmail(gc, subject, from, to, url);
+	return NULL;
+}
+
 static void buddyListAddBuddy(PurpleAccount *account, const char *username, const char *group, const char *alias){
 	std::cout << "BUDDY LIST ADD BUDDY REQUEST\n";
 }
@@ -361,11 +367,11 @@ static PurpleNotifyUiOps notifyUiOps =
 static PurpleNotifyUiOps notifyUiOps =
 {
 		NULL,
+		notifyEmail,
 		NULL,
 		NULL,
 		NULL,
 		NULL,
-		NULL,
 		notify_user_info,
 		NULL,
 		NULL,
@@ -940,6 +946,28 @@ void GlooxMessageHandler::purpleConversa
 	}
 }
 
+void GlooxMessageHandler::notifyEmail(PurpleConnection *gc,const char *subject, const char *from,const char *to, const char *url) {
+	if (protocol()->notifyUsername().empty())
+		return;
+	PurpleAccount *account = purple_connection_get_account(gc);
+	User *user = userManager()->getUserByAccount(account);
+	if (user!=NULL) {
+		std::string text;
+		if (subject)
+			text+=std::string(subject) + " ";
+		if (from)
+			text+=std::string(from) + " ";
+		if (to)
+			text+=std::string(to) + " ";
+		if (url)
+			text+=std::string(url) + " ";
+		Message s(Message::Chat, user->jid(), text);
+		s.setFrom(protocol()->notifyUsername()+"@"+jid()+"/bot");
+		j->send(s);
+	}
+}
+
+
 void GlooxMessageHandler::purpleConversationWriteChat(PurpleConversation *conv, const char *who, const char *message, PurpleMessageFlags flags, time_t mtime){
 	if (who==NULL)
 		return;
============================================================
--- main.h	cb907f165977326df8fd0d0ee1b7f75b75dc2ad1
+++ main.h	b98de4bc7f20a8b7351934aca86892150f5c4adf
@@ -170,6 +170,7 @@ public:
 	void purpleAuthorizeClose(void *data);
 	void purpleFileReceiveRequest(PurpleXfer *xfer);
 	void purpleFileReceiveComplete(PurpleXfer *xfer);
+	void notifyEmail(PurpleConnection *gc,const char *subject, const char *from,const char *to, const char *url);
 
 	// MessageHandler
 	void handleMessage (const Message &msg, MessageSession *session=0);
============================================================
--- protocols/abstractprotocol.h	ed090b52d257490fab1eef28f81a6dbcb047ac8e
+++ protocols/abstractprotocol.h	40e96f5fedad83c1d88b78f0d1d136a5543c9958
@@ -69,6 +69,10 @@ class AbstractProtocol
 		 * Returns true if this jid is jid of MUC
 		 */
 		virtual bool isMUC(User *user, const std::string &jid) = 0 ;
+		/*
+		 * Returns the username of contact from which notifications will be sent
+		 */
+		virtual std::string notifyUsername() { return ""; }
 };
 
 #endif
============================================================
--- protocols/facebook.h	5c75c40ab867d47637f8fbe9a929a781221dc7fb
+++ protocols/facebook.h	8fe7c732eb015a334d8e9d7631d197cc9c98d5b4
@@ -40,6 +40,7 @@ class FacebookProtocol : AbstractProtoco
 		std::string text(const std::string &key);
 		Tag *getVCardTag(User *user, GList *vcardEntries);
 		bool isMUC(User *user, const std::string &jid) { return false; }
+		std::string notifyUsername() { return "info"; }
 		
 		std::string replace(std::string &str, const char *string_to_replace, const char *new_string);
 	


More information about the Commits mailing list