CVS: sylpheedclaws/plugins/notification/src notification_popup.c,1.1.2.11,1.1.2.12

[email protected] Sun, 17 Dec 2006 19:17:04 +0000
Newsgroups gmane.mail.sylpheed.claws.cvs
Message-ID <[email protected]>
Update of /pack/anoncvs/sylpheedclaws/plugins/notification/src
In directory sunsite.dk:/tmp/cvs-serv22716/src

Modified Files:
      Tag: gtk2
	notification_popup.c 
Log Message:
2006-12-17 [holger]	0.7cvs3

	* src/notification_popup.c
		If a single mail message arrived,
		show its from and subject headers in popup. 

Index: notification_popup.c
===================================================================
RCS file: /pack/anoncvs/sylpheedclaws/plugins/notification/src/Attic/notification_popup.c,v
retrieving revision 1.1.2.11
retrieving revision 1.1.2.12
diff -u -d -r1.1.2.11 -r1.1.2.12
--- notification_popup.c	2006/11/07 10:57:10	1.1.2.11
+++ notification_popup.c	2006/12/17 19:16:58	1.1.2.12
@@ -76,6 +76,8 @@
 					       NotificationFolderType);
 static void default_action_cb(NotifyNotification*, const char*,
 			      void*);
+static gchar* notification_libnotify_sanitize_str(gchar*);
+
 #else /* !HAVE_LIBNOTIFY */
 static gboolean notification_popup_add_msg(MsgInfo*);
 static gboolean notification_popup_create(MsgInfo*);
@@ -242,8 +244,10 @@
 {
   GdkPixbuf *pixbuf;
   NotificationPopup *ppopup;
-  gchar *summary;
-  gchar *text;
+  gchar *summary = NULL;
+  gchar *text = NULL;
+  gchar *subj = NULL;
+  gchar *from = NULL;
 
   ppopup = &(popup[nftype]);
 
@@ -258,28 +262,33 @@
 
   switch(nftype) {
   case F_TYPE_MAIL:
-    summary = "Mail message";
-    text    = "A new message arrived.";
+    summary = "New Mail message";
+    from    = notification_libnotify_sanitize_str(msginfo->from);
+    subj    = notification_libnotify_sanitize_str(msginfo->subject);
+    text    = g_strconcat(from,"\n\n",subj,NULL);
+    if(from) g_free(from);
+    if(subj) g_free(subj);
     break;
   case F_TYPE_NEWS:
-    summary = "News message";
-    text    = "A new mesesage arrived";
+    summary = "New News message";
+    text    = g_strdup("A new mesesage arrived");
     break;
   case F_TYPE_CALENDAR:
-    summary = "Calendar message";
-    text    = "A new calendar message arrived";
+    summary = "New Calendar message";
+    text    = g_strdup("A new calendar message arrived");
     break;
   case F_TYPE_RSS:
-    summary = "RSS news feed";
-    text = "A new article in a RSS feed arrived";
+    summary = "New RSS feed article";
+    text = g_strdup("A new article in a RSS feed arrived");
     break;
   default:
-    summary = "Unknown message";
-    text = "Unknown message type arrived";
+    summary = "New unknown message";
+    text = g_strdup("Unknown message type arrived");
     break;
   }
 
   ppopup->notification = notify_notification_new(summary, text, NULL, NULL);
+  g_free(text);
   if(ppopup->notification == NULL) {
     debug_print("Notification Plugin: Failed to create a new "
 		"notification.\n");
@@ -359,7 +368,6 @@
     /* Should not happen */
     debug_print("Notification Plugin: Unknown folder type ignored\n");
     return FALSE;
-    break;
   }
 
   retval = notify_notification_update(ppopup->notification, summary, 
@@ -383,6 +391,45 @@
   return TRUE;
 }
 
+#define STR_MAX_LEN 511
+/* Returns a newly allocated string which needs to be freed */
+static gchar* notification_libnotify_sanitize_str(gchar *in)
+{
+  gint i_out;
+  gchar tmp_str[STR_MAX_LEN+1];
+
+  if(in == NULL) return NULL;
+
+  i_out = 0;
+  while(*in) {
+    if(!g_ascii_isprint(*in)) {
+      in++;
+      continue;
+    }
+    if(*in == '<') {
+      if(i_out+3 >= STR_MAX_LEN) break;
+      memcpy(&(tmp_str[i_out]),"&lt;",4);
+      in++; i_out += 4;
+    }
+    else if(*in == '>') {
+      if(i_out+3 >= STR_MAX_LEN) break;
+      memcpy(&(tmp_str[i_out]),"&gt;",4);
+      in++; i_out += 4;
+    }
+    else if(*in == '&') {
+      if(i_out+4 >= STR_MAX_LEN) break;
+      memcpy(&(tmp_str[i_out]),"&amp;",5);
+      in++; i_out += 5;
+    }
+    else {
+      if(i_out >= STR_MAX_LEN) break;
+      tmp_str[i_out++] = *in++;
+    }
+  }
+  tmp_str[i_out] = '\0';
+  return strdup(tmp_str);
+}
+
 #else /* !HAVE_LIBNOTIFY */
 static gboolean notification_popup_add_msg(MsgInfo *msginfo)
 {
@@ -484,6 +531,6 @@
   }
   return TRUE;
 }
-#endif /* HAVE_LIBNOTIFY */
+#endif /* !HAVE_LIBNOTIFY */
 
 #endif /* NOTIFICATION_POPUP */