[Commits] main.c 1.115.2.249 1.115.2.250 main.h 1.7.2.20 1.7.2.21 inc.c 1.149.2.106 1.149.2.107 procmsg.c 1.150.2.123 1.150.2.124

wwp at claws-mail.org wwp at claws-mail.org
Sat Jun 2 11:06:29 CEST 2012


Update of /home/claws-mail/claws/src
In directory srv:/tmp/cvs-serv32044/src

Modified Files:
      Tag: gtk2
	main.c main.h inc.c procmsg.c 
Log Message:
2012-06-02 [wwp]	3.8.0cvs52

	* doc/man/claws-mail.1
	* src/main.c
	* src/main.h
	* src/inc.c
	* src/procmsg.c
	* src/gtk/about.c
		Introduce a new feature: basic session statistics (from the about dialog
		or the command-line).

Index: inc.c
===================================================================
RCS file: /home/claws-mail/claws/src/inc.c,v
retrieving revision 1.149.2.106
retrieving revision 1.149.2.107
diff -u -d -r1.149.2.106 -r1.149.2.107
--- inc.c	27 May 2012 17:30:51 -0000	1.149.2.106
+++ inc.c	2 Jun 2012 09:06:27 -0000	1.149.2.107
@@ -78,6 +78,8 @@
 #endif
 #endif
 
+extern SessionStats session_stats;
+
 static GList *inc_dialog_list = NULL;
 
 guint inc_lock_count = 0;
@@ -88,6 +90,7 @@
 
 #define MSGBUFSIZE	8192
 
+static void inc_update_stats(gint new_msgs);
 static void inc_finished		(MainWindow		*mainwin,
 					 gboolean		 new_messages,
 					 gboolean		 autocheck);
@@ -153,7 +156,15 @@
 
 static void inc_notify_cmd		(gint new_msgs, 
  					 gboolean notify);
-	
+
+static void inc_update_stats(gint new_msgs)
+{
+	/* update session statistics */
+	session_stats.received += new_msgs;
+fprintf(stdout, "++ STATS ++ INC %d %d\n", session_stats.received, new_msgs);
+fflush(stdout);
+}
+
 /**
  * inc_finished:
  * @mainwin: Main window.
@@ -214,6 +225,7 @@
 			new_msgs += account_new_msgs;
 	}
 
+	inc_update_stats(new_msgs);
 	inc_finished(mainwin, new_msgs > 0, FALSE);
 	main_window_unlock(mainwin);
  	inc_notify_cmd(new_msgs, notify);
@@ -307,6 +319,7 @@
 
 	new_msgs = inc_account_mail_real(mainwin, account);
 
+	inc_update_stats(new_msgs);
 	inc_finished(mainwin, new_msgs > 0, FALSE);
 	main_window_unlock(mainwin);
 	inc_autocheck_timer_set();
@@ -335,6 +348,7 @@
 
 	list = account_get_list();
 	if (!list) {
+		inc_update_stats(new_msgs);
 		inc_finished(mainwin, new_msgs > 0, autocheck);
 		main_window_unlock(mainwin);
  		inc_notify_cmd(new_msgs, notify);
@@ -390,6 +404,7 @@
 		new_msgs += inc_start(inc_dialog);
 	}
 
+	inc_update_stats(new_msgs);
 	inc_finished(mainwin, new_msgs > 0, autocheck);
 	main_window_unlock(mainwin);
  	inc_notify_cmd(new_msgs, notify);
@@ -1407,7 +1422,6 @@
 
 static void inc_notify_cmd(gint new_msgs, gboolean notify)
 {
-
 #ifndef MAEMO
 	gchar *buf, *numpos, *ret_str;
 	gssize by_read = 0, by_written = 0;

Index: main.h
===================================================================
RCS file: /home/claws-mail/claws/src/main.h,v
retrieving revision 1.7.2.20
retrieving revision 1.7.2.21
diff -u -d -r1.7.2.20 -r1.7.2.21
--- main.h	27 May 2012 17:30:51 -0000	1.7.2.20
+++ main.h	2 Jun 2012 09:06:27 -0000	1.7.2.21
@@ -30,6 +30,7 @@
 #include <hildon-widgets/hildon-window.h>
 #endif
 #endif
+#include <sys/time.h>
 
 extern gchar *prog_version;
 extern gboolean debug_mode;
@@ -38,6 +39,17 @@
 extern HildonProgram *hildon_program;
 #endif
 
+typedef struct _SessionStats SessionStats;
+
+struct _SessionStats
+{
+	gint received;
+	gint sent;
+	gint replied;
+	gint forwarded;
+	time_t time_started;
+};
+
 void app_will_exit	(GtkWidget *widget, gpointer data);
 gboolean clean_quit	(gpointer data);
 gboolean claws_is_exiting(void);

Index: main.c
===================================================================
RCS file: /home/claws-mail/claws/src/main.c,v
retrieving revision 1.115.2.249
retrieving revision 1.115.2.250
diff -u -d -r1.115.2.249 -r1.115.2.250
--- main.c	27 May 2012 17:30:51 -0000	1.115.2.249
+++ main.c	2 Jun 2012 09:06:27 -0000	1.115.2.250
@@ -207,6 +207,8 @@
 	gboolean search_recursive;
 	gboolean status;
 	gboolean status_full;
+	gboolean statistics;
+	gboolean reset_statistics;
 	GPtrArray *status_folders;
 	GPtrArray *status_full_folders;
 	gboolean send;
@@ -219,6 +221,10 @@
 	const gchar *target;
 } cmd;
 
+SessionStats session_stats;
+
+static void reset_statistics(void);
+		
 static void parse_cmd_opt(int argc, char *argv[]);
 
 static gint prohibit_duplicate_launch	(void);
@@ -1031,6 +1037,16 @@
 }
 #endif
 
+static void reset_statistics(void)
+{
+	/* (re-)initialize session statistics */
+	session_stats.received = 0;
+	session_stats.sent = 0;
+	session_stats.replied = 0;
+	session_stats.forwarded = 0;
+	session_stats.time_started = time(NULL);
+}
+		
 int main(int argc, char *argv[])
 {
 #ifdef MAEMO
@@ -1106,7 +1122,8 @@
 		return 0;
 	}
 
-	if (cmd.status || cmd.status_full || cmd.search) {
+	if (cmd.status || cmd.status_full || cmd.search ||
+		cmd.statistics || cmd.reset_statistics) {
 		puts("0 Claws Mail not running.");
 		lock_socket_remove();
 		return 0;
@@ -1117,6 +1134,8 @@
 	if (!g_thread_supported())
 		g_thread_init(NULL);
 
+	reset_statistics();
+	
 	gtk_set_locale();
 	gtk_init(&argc, &argv);
 
@@ -2000,6 +2019,10 @@
 			cmd.online_mode = ONLINE_MODE_ONLINE;
 		} else if (!strncmp(argv[i], "--offline", 9)) {
 			cmd.online_mode = ONLINE_MODE_OFFLINE;
+		} else if (!strncmp(argv[i], "--statistics", 12)) {
+			cmd.statistics = TRUE;
+		} else if (!strncmp(argv[i], "--reset-statistics", 18)) {
+			cmd.reset_statistics = TRUE;
 		} else if (!strncmp(argv[i], "--help", 6) ||
 			   !strncmp(argv[i], "-h", 2)) {
 			gchar *base = g_path_get_basename(argv[0]);
@@ -2028,6 +2051,8 @@
  			g_print("%s\n", _("  --status [folder]...   show the total number of messages"));
  			g_print("%s\n", _("  --status-full [folder]...\n"
  			                  "                         show the status of each folder"));
+ 			g_print("%s\n", _("  --statistics           show session statistics"));
+ 			g_print("%s\n", _("  --reset-statistics     reset session statistics"));
 			g_print("%s\n", _("  --select folder[/msg]  jumps to the specified folder/message\n" 
 			                  "                         folder is a folder id like 'folder/sub_folder'"));
 			g_print("%s\n", _("  --online               switch to online mode"));
@@ -2373,6 +2398,16 @@
  		}
 	} else if (cmd.exit) {
 		fd_write_all(uxsock, "exit\n", 5);
+	} else if (cmd.statistics) {
+		gchar buf[BUFSIZ];
+		fd_write(uxsock, "statistics\n", 11);
+ 		for (;;) {
+ 			fd_gets(uxsock, buf, sizeof(buf));
+ 			if (!strncmp(buf, ".\n", 2)) break;
+ 			fputs(buf, stdout);
+ 		}
+	} else if (cmd.reset_statistics) {
+		fd_write(uxsock, "reset_statistics\n", 17);
 	} else if (cmd.target) {
 		gchar *str = g_strdup_printf("select %s\n", cmd.target);
 		fd_write_all(uxsock, str, strlen(str));
@@ -2532,6 +2567,48 @@
  		fd_write_all(sock, ".\n", 2);
  		g_free(status);
  		if (folders) g_ptr_array_free(folders, TRUE);
+	} else if (!strncmp(buf, "statistics", 10)) {
+		gchar tmp[BUFSIZ];
+
+		g_snprintf(tmp, sizeof(tmp), _("Session statistics\n"));
+ 		fd_write_all(sock, tmp, strlen(tmp));
+
+		g_snprintf(tmp, sizeof(tmp), _("Started: %s\n"),
+				ctime(&session_stats.time_started));
+ 		fd_write_all(sock, tmp, strlen(tmp));
+
+		g_snprintf(tmp, sizeof(tmp), _("Incoming traffic\n"));
+ 		fd_write_all(sock, tmp, strlen(tmp));
+
+		g_snprintf(tmp, sizeof(tmp), _("Received messages: %d\n"),
+				session_stats.received);
+ 		fd_write_all(sock, tmp, strlen(tmp));
+
+ 		fd_write_all(sock, "\n", 1);
+
+		g_snprintf(tmp, sizeof(tmp), _("Outgoing traffic\n"));
+ 		fd_write_all(sock, tmp, strlen(tmp));
+
+		g_snprintf(tmp, sizeof(tmp), _("New/redirected messages: %d\n"),
+				session_stats.sent);
+ 		fd_write_all(sock, tmp, strlen(tmp));
+
+		g_snprintf(tmp, sizeof(tmp), _("Replied messages: %d\n"),
+				session_stats.replied);
+ 		fd_write_all(sock, tmp, strlen(tmp));
+
+		g_snprintf(tmp, sizeof(tmp), _("Forwarded messages: %d\n"),
+				session_stats.forwarded);
+ 		fd_write_all(sock, tmp, strlen(tmp));
+
+		g_snprintf(tmp, sizeof(tmp), _("Total outgoing messages: %d\n"),
+				(session_stats.sent + session_stats.replied +
+				 session_stats.forwarded));
+ 		fd_write_all(sock, tmp, strlen(tmp));
+
+ 		fd_write_all(sock, ".\n", 2);
+	} else if (!strncmp(buf, "reset_statistics", 16)) {
+		reset_statistics();
 	} else if (!strncmp(buf, "select ", 7)) {
 		const gchar *target = buf+7;
 		mainwindow_jump_to(target, TRUE);

Index: procmsg.c
===================================================================
RCS file: /home/claws-mail/claws/src/procmsg.c,v
retrieving revision 1.150.2.123
retrieving revision 1.150.2.124
diff -u -d -r1.150.2.123 -r1.150.2.124
--- procmsg.c	27 May 2012 17:30:56 -0000	1.150.2.123
+++ procmsg.c	2 Jun 2012 09:06:27 -0000	1.150.2.124
@@ -49,6 +49,8 @@
 #include "timing.h"
 #include "inc.h"
 
+extern SessionStats session_stats;
+
 static gint procmsg_send_message_queue_full(const gchar *file, gboolean keep_session, gchar **errstr,
 					    FolderItem *queue, gint msgnum, gboolean *queued_removed);
 static void procmsg_update_unread_children	(MsgInfo 	*info,
@@ -1761,6 +1763,19 @@
 
 	fclose(fp);
 
+	/* update session statistics */
+	if (mailval == 0 && newsval == 0) {
+		/* update session stats */
+		if (replymessageid)
+			session_stats.replied++;
+		else if (fwdmessageid)
+			session_stats.forwarded++;
+		else
+			session_stats.sent++;
+fprintf(stdout, "++ STATS ++ SENT %d %d %d\n", session_stats.sent, session_stats.replied, session_stats.forwarded);
+fflush(stdout);
+	}
+
 	/* save message to outbox */
 	if (mailval == 0 && newsval == 0 && savecopyfolder) {
 		FolderItem *outbox;



More information about the Commits mailing list