Re: [PATCH] X-Operating System in outgoing mail's header
- From: christophe barbe <christophe barbe ml online fr>
- To: balsa mailing-list <balsa-list gnome org>
- Subject: Re: [PATCH] X-Operating System in outgoing mail's header
- Date: Tue, 28 Aug 2001 00:20:40 +0200
Here's a rework of my system Id patch.
This patch sets a better default value and fix a bug when using an empty
format string.
Please try it, read it and give me feedback.
I would be please to learn with this patch before trying to code biger one
(and certainly more usefull).
Christophe
--
Christophe Barbé <christophe.barbe@online.fr>
GnuPG FingerPrint: E0F6 FADF 2A5C F072 6AF8 F67A 8F45 2F1E D72C B41E
diff -u -r -N balsa/libbalsa/message.h balsa-2/libbalsa/message.h
--- balsa/libbalsa/message.h Tue Aug 28 00:10:58 2001
+++ balsa-2/libbalsa/message.h Tue Aug 28 00:11:44 2001
@@ -187,7 +187,8 @@
LibBalsaMailbox* outbox,
LibBalsaMailbox* fccbox,
gint encoding, gchar* smtp_server,
- auth_context_t smtp_authctx);
+ auth_context_t smtp_authctx,
+ gchar* SystemId);
#else
gboolean libbalsa_message_send(LibBalsaMessage* message,
LibBalsaMailbox* outbox,
diff -u -r -N balsa/libbalsa/misc.h balsa-2/libbalsa/misc.h
--- balsa/libbalsa/misc.h Tue Aug 28 00:10:59 2001
+++ balsa-2/libbalsa/misc.h Tue Aug 28 00:11:44 2001
@@ -47,7 +47,8 @@
#if ENABLE_ESMTP
gboolean libbalsa_process_queue(LibBalsaMailbox* outbox, gint encoding,
gchar* smtp_server,
- auth_context_t smtp_authctx);
+ auth_context_t smtp_authctx,
+ gchar* SystemId);
#else
gboolean libbalsa_process_queue(LibBalsaMailbox* outbox, gint encoding);
#endif
diff -u -r -N balsa/libbalsa/send.c balsa-2/libbalsa/send.c
--- balsa/libbalsa/send.c Tue Aug 28 00:10:59 2001
+++ balsa-2/libbalsa/send.c Tue Aug 28 00:11:44 2001
@@ -1,4 +1,5 @@
/* -*-mode:c; c-style:k&r; c-basic-offset:4; -*- */
+/* vim:set ts=4 sw=4 ai et: */
/* Balsa E-Mail Client
*
* Copyright (C) 1997-2001 Stuart Parmenter and others,
@@ -346,11 +347,12 @@
gboolean
libbalsa_message_send(LibBalsaMessage* message, LibBalsaMailbox* outbox,
LibBalsaMailbox* fccbox, gint encoding,
- gchar* smtp_server, auth_context_t smtp_authctx)
+ gchar* smtp_server, auth_context_t smtp_authctx,
+ gchar* SystemId)
{
if (message != NULL)
libbalsa_message_queue(message, outbox, fccbox, encoding);
- return libbalsa_process_queue(outbox, encoding, smtp_server, smtp_authctx);
+ return libbalsa_process_queue(outbox, encoding, smtp_server, smtp_authctx, SystemId);
}
#else
gboolean
@@ -430,7 +432,7 @@
*/
gboolean
libbalsa_process_queue(LibBalsaMailbox* outbox, gint encoding,
- gchar* smtp_server, auth_context_t smtp_authctx)
+ gchar* smtp_server, auth_context_t smtp_authctx, gchar* SystemId)
{
MessageQueueItem *new_message;
SendMessageInfo *send_message_info;
@@ -562,6 +564,14 @@
if (bcc_message)
smtp_set_header (bcc_message, "Disposition-Notification-To",
phrase, mailbox);
+ }
+
+ if ((SystemId!=NULL) && (SystemId[0]!=0)) {
+ phrase = libbalsa_address_get_phrase(queu->dispnotify_to);
+ mailbox = libbalsa_address_get_mailbox(queu->dispnotify_to, 0);
+ smtp_set_header (message, "X-Operating-System", SystemId);
+ if (bcc_message)
+ smtp_set_header (bcc_message, "X-Operating-System", SystemId);
}
#endif
diff -u -r -N balsa/src/Makefile.am balsa-2/src/Makefile.am
--- balsa/src/Makefile.am Tue Aug 28 00:11:19 2001
+++ balsa-2/src/Makefile.am Tue Aug 28 00:11:44 2001
@@ -54,7 +54,9 @@
toolbar-prefs.c \
toolbar-prefs.h \
toolbar-factory.c \
- toolbar-factory.h
+ toolbar-factory.h \
+ system-id.c \
+ system-id.h
balsa_IDL_SOURCES = \
balsa-common.c \
diff -u -r -N balsa/src/balsa-app.c balsa-2/src/balsa-app.c
--- balsa/src/balsa-app.c Tue Aug 28 00:11:19 2001
+++ balsa-2/src/balsa-app.c Tue Aug 28 00:11:44 2001
@@ -1,4 +1,5 @@
/* -*-mode:c; c-style:k&r; c-basic-offset:4; -*- */
+/* vim:set ts=4 sw=4 ai et: */
/* Balsa E-Mail Client
* Copyright (C) 1997-2001 Stuart Parmenter and others,
* See the file AUTHORS for a list.
@@ -340,6 +341,10 @@
balsa_app.notify_new_mail_sound = 1;
balsa_app.notify_new_mail_dialog = 0;
+
+ /* System Identification */
+ balsa_app.SystemIdFormat=NULL;
+ balsa_app.SystemId=NULL;
/* Tooltips */
balsa_app.tooltips = gtk_tooltips_new();
diff -u -r -N balsa/src/balsa-app.h balsa-2/src/balsa-app.h
--- balsa/src/balsa-app.h Tue Aug 28 00:11:19 2001
+++ balsa-2/src/balsa-app.h Tue Aug 28 00:11:44 2001
@@ -22,6 +22,8 @@
#ifndef __BALSA_APP_H__
#define __BALSA_APP_H__
+#include <sys/utsname.h>
+
#include <gnome.h>
#include "libbalsa.h"
#include "identity.h"
@@ -322,6 +324,11 @@
/* Tooltips */
GtkTooltips *tooltips;
+
+ /* System Identification */
+ struct utsname uname;
+ char * SystemIdFormat;
+ char * SystemId;
#ifdef BALSA_MDN_REPLY
/* how to act if a MDN request is received */
diff -u -r -N balsa/src/balsa-message.c balsa-2/src/balsa-message.c
--- balsa/src/balsa-message.c Tue Aug 28 00:11:20 2001
+++ balsa-2/src/balsa-message.c Tue Aug 28 00:11:45 2001
@@ -2453,7 +2453,8 @@
libbalsa_message_send(mdn, balsa_app.outbox, NULL,
balsa_app.encoding_style,
balsa_app.smtp_server,
- balsa_app.smtp_authctx);
+ balsa_app.smtp_authctx,
+ balsa_app.SystemId);
#else
libbalsa_message_send(mdn, balsa_app.outbox, NULL,
balsa_app.encoding_style);
@@ -2612,7 +2613,8 @@
libbalsa_message_send(send_msg, balsa_app.outbox, NULL,
balsa_app.encoding_style,
balsa_app.smtp_server,
- balsa_app.smtp_authctx);
+ balsa_app.smtp_authctx,
+ balsa_app.SystemId);
#else
libbalsa_message_send(send_msg, balsa_app.outbox, NULL,
balsa_app.encoding_style);
diff -u -r -N balsa/src/main-window.c balsa-2/src/main-window.c
--- balsa/src/main-window.c Tue Aug 28 00:11:21 2001
+++ balsa-2/src/main-window.c Tue Aug 28 00:11:45 2001
@@ -1600,7 +1600,8 @@
{
#if ENABLE_ESMTP
libbalsa_process_queue(balsa_app.outbox, balsa_app.encoding_style,
- balsa_app.smtp_server, balsa_app.smtp_authctx);
+ balsa_app.smtp_server, balsa_app.smtp_authctx,
+ balsa_app.SystemId);
#else
libbalsa_process_queue(balsa_app.outbox, balsa_app.encoding_style);
#endif
diff -u -r -N balsa/src/main.c balsa-2/src/main.c
--- balsa/src/main.c Tue Aug 28 00:11:21 2001
+++ balsa-2/src/main.c Tue Aug 28 00:11:45 2001
@@ -1,4 +1,5 @@
/* -*-mode:c; c-style:k&r; c-basic-offset:4; -*- */
+/* vim:set ts=4 sw=4 ai et: */
/* Balsa E-Mail Client
* Copyright (C) 1997-2001 Stuart Parmenter and others,
* See the file AUTHORS for a list.
@@ -54,6 +55,7 @@
#include "main.h"
#include "information.h"
#include "pop3.h"
+#include "system-id.h"
#include "libinit_balsa/init_balsa.h"
@@ -301,6 +303,10 @@
/* checking for valid config files */
config_init();
+
+ /* set X-Operating-System string */
+ init_SystemId();
+ update_SystemId();
/* load mailboxes */
mailboxes_init();
diff -u -r -N balsa/src/pref-manager.c balsa-2/src/pref-manager.c
--- balsa/src/pref-manager.c Tue Aug 28 00:11:22 2001
+++ balsa-2/src/pref-manager.c Tue Aug 28 00:11:46 2001
@@ -1,4 +1,5 @@
/* -*-mode:c; c-style:k&r; c-basic-offset:4; -*- */
+/* vim:set ts=4 sw=4 ai et: */
/* Balsa E-Mail Client
* Copyright (C) 1997-2001 Stuart Parmenter and others,
* See the file AUTHORS for a list.
@@ -33,6 +34,7 @@
#include "spell-check.h"
#include "address-book-config.h"
#include "quote-color.h"
+#include "system-id.h"
/* FIXME: Mutt dependency for ENC7BIT ENC8BIT ENCQUOTEDPRINTABLE consts*/
#include "../libmutt/mime.h"
@@ -93,6 +95,10 @@
GtkWidget *debug_message_menu;
GtkWidget *fatal_message_menu;
+ /* System Identification */
+ GtkWidget *SystemIdFormat;
+ GtkWidget *SystemId_preview;
+
/* arp */
GtkWidget *quote_str;
@@ -164,6 +170,7 @@
static void mailbox_timer_modified_cb(GtkWidget * widget, GtkWidget * pbox);
static void wrap_modified_cb(GtkWidget * widget, GtkWidget * pbox);
static void pgdown_modified_cb(GtkWidget * widget, GtkWidget * pbox);
+static void SystemId_preview_cb(GtkWidget * widget, GtkWidget * pbox);
static void spelling_optionmenu_cb(GtkItem * menuitem, gpointer data);
static void set_default_address_book_cb(GtkWidget * button, gpointer data);
static void imap_toggled_cb(GtkWidget * widget, GtkWidget * pbox);
@@ -371,6 +378,10 @@
gtk_signal_connect(GTK_OBJECT(pui->reply_strip_html_parts), "toggled",
GTK_SIGNAL_FUNC(properties_modified_cb), property_box);
+ /* System Identification */
+ gtk_signal_connect(GTK_OBJECT(pui->SystemIdFormat), "changed",
+ GTK_SIGNAL_FUNC(SystemId_preview_cb), property_box);
+
/* arp */
gtk_signal_connect(GTK_OBJECT(pui->quote_str), "changed",
GTK_SIGNAL_FUNC(properties_modified_cb),
@@ -681,6 +692,15 @@
GPOINTER_TO_INT(gtk_object_get_user_data(GTK_OBJECT(menu_item)));
/*
+ * System information
+ */
+ tmp=balsa_app.SystemIdFormat;
+ balsa_app.SystemIdFormat=g_strdup(gtk_entry_get_text(
+ GTK_ENTRY(pui->SystemIdFormat)));
+ update_SystemId();
+ g_free(tmp);
+
+ /*
* close window and free memory
*/
config_save();
@@ -890,6 +910,17 @@
gtk_menu_set_active(GTK_MENU(pui->debug_message_menu),
balsa_app.debug_message);
+ /* System information */
+ gtk_entry_set_text(GTK_ENTRY(pui->SystemIdFormat),
+ balsa_app.SystemIdFormat);
+ tmp=get_SystemId_tooltip(balsa_app.SystemIdFormat);
+ gtk_tooltips_set_tip(balsa_app.tooltips, pui->SystemIdFormat,
+ tmp, "set X-Operating-System field in outgoing mail");
+ g_free(tmp);
+ tmp=get_SystemId(balsa_app.SystemIdFormat);
+ gtk_label_set_text(GTK_LABEL (pui->SystemId_preview), tmp);
+ g_free(tmp);
+
}
static void
@@ -1421,6 +1452,8 @@
GtkWidget *frame2;
GtkWidget *table;
GtkTable *table2;
+ GtkTable *table3;
+ GtkTable *table4;
GtkObject *spinbutton_adj;
GtkWidget *label;
GtkWidget *vbox1, *vbox2;
@@ -1477,6 +1510,16 @@
gtk_box_pack_start(GTK_BOX(vbox2), pui->always_queue_sent_mail,
FALSE, TRUE, 0);
+ table3 = GTK_TABLE(gtk_table_new(3, 2, FALSE));
+ gtk_container_add(GTK_CONTAINER(vbox2), GTK_WIDGET(table3));
+ gtk_container_set_border_width(GTK_CONTAINER(table3), 2);
+ pui->SystemIdFormat = attach_entry(_("System identification :"),
+ 4, table3);
+
+ pui->SystemId_preview = gtk_label_new("");
+ gtk_box_pack_start(GTK_BOX(vbox2), pui->SystemId_preview,
+ FALSE, TRUE, 0);
+
frame2 = gtk_frame_new(_("Encoding"));
gtk_box_pack_start(GTK_BOX(vbox1), frame2, FALSE, FALSE, 0);
gtk_container_set_border_width(GTK_CONTAINER(frame2), 5);
@@ -2214,6 +2257,20 @@
gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(pui->pgdownmod));
gtk_widget_set_sensitive(GTK_WIDGET(pui->pgdown_percent), newstate);
+ properties_modified_cb(widget, pbox);
+}
+
+static void
+SystemId_preview_cb(GtkWidget * widget, GtkWidget * pbox)
+{
+ gchar * tmp, *format;
+
+ format=g_strdup(gtk_entry_get_text(GTK_ENTRY(pui->SystemIdFormat)));
+ tmp=get_SystemId(format);
+ gtk_label_set_text(GTK_LABEL (pui->SystemId_preview), tmp);
+ g_free(tmp);
+ g_free(format);
+
properties_modified_cb(widget, pbox);
}
diff -u -r -N balsa/src/save-restore.c balsa-2/src/save-restore.c
--- balsa/src/save-restore.c Tue Aug 28 00:11:22 2001
+++ balsa-2/src/save-restore.c Tue Aug 28 00:11:46 2001
@@ -1,4 +1,5 @@
/* -*-mode:c; c-style:k&r; c-basic-offset:4; -*- */
+/* vim:set ts=4 sw=4 ai et: */
/* Balsa E-Mail Client
* Copyright (C) 1997-2001 Stuart Parmenter and others,
* See the file AUTHORS for a list.
@@ -655,6 +656,7 @@
gnome_config_get_bool("StripHtmlInReply=true");
balsa_app.always_queue_sent_mail = d_get_gint("AlwaysQueueSentMail", 0);
+ balsa_app.SystemIdFormat = gnome_config_get_string("SystemIdFormat=%s %r");
gnome_config_pop_prefix();
@@ -878,6 +880,8 @@
gnome_config_set_bool("StripHtmlInReply", balsa_app.reply_strip_html);
gnome_config_set_int("AlwaysQueueSentMail", balsa_app.always_queue_sent_mail);
+ gnome_config_set_string("SystemIdFormat", balsa_app.SystemIdFormat);
+
gnome_config_pop_prefix();
/* Compose window ... */
diff -u -r -N balsa/src/sendmsg-window.c balsa-2/src/sendmsg-window.c
--- balsa/src/sendmsg-window.c Tue Aug 28 00:11:23 2001
+++ balsa-2/src/sendmsg-window.c Tue Aug 28 00:11:46 2001
@@ -2042,7 +2042,8 @@
successful = libbalsa_message_send(message, balsa_app.outbox, fcc,
balsa_app.encoding_style,
balsa_app.smtp_server,
- balsa_app.smtp_authctx);
+ balsa_app.smtp_authctx,
+ balsa_app.SystemId);
#else
successful = libbalsa_message_send(message, balsa_app.outbox, fcc,
balsa_app.encoding_style);
diff -u -r -N balsa/src/system-id.c balsa-2/src/system-id.c
--- balsa/src/system-id.c Thu Jan 1 01:00:00 1970
+++ balsa-2/src/system-id.c Tue Aug 28 00:11:46 2001
@@ -0,0 +1,141 @@
+/* -*-mode:c; c-style:k&r; c-basic-offset:4; -*- */
+/* vim:set ts=4 sw=4 ai et: */
+/* Balsa E-Mail Client
+ * Copyright (C) 1997-2001 Stuart Parmenter and others,
+ * See the file AUTHORS for a list.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ */
+
+#include <stdio.h>
+#include <sys/utsname.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "config.h"
+#include "balsa-app.h"
+
+#include <gnome.h>
+#include <glib.h>
+
+int init_SystemId(void)
+{
+ if (uname(&balsa_app.uname)==-1) {
+ perror("uname");
+ return 1;
+ }
+ return 0;
+}
+
+char * get_SystemId(char * format)
+{
+ gchar ** fields;
+ int len, i;
+ int previous, insert;
+ char *s, *result, *incstr=NULL;
+
+ if ((len=strlen(format))==0) return g_strdup("");
+
+ fields=g_strsplit((gchar *)format, "%", 0);
+
+ for (i=1; fields[i]!=NULL; i++) {
+ switch(fields[i][0]) {
+ case 'm': len+=strlen(balsa_app.uname.machine)-2; break;
+ case 'n': len+=strlen(balsa_app.uname.nodename)-2; break;
+ case 'r': len+=strlen(balsa_app.uname.release)-2; break;
+ case 's': len+=strlen(balsa_app.uname.sysname)-2; break;
+ case 'v': len+=strlen(balsa_app.uname.version)-2; break;
+ default:
+ break;
+ }
+ }
+
+ result=(char *)malloc((len+1)*sizeof(char));
+ if (result==NULL) {
+ fprintf(stderr, "unable to allocate memory\n");
+ return NULL;
+ }
+
+ previous=0;
+ s=result;
+ for (i=1; fields[i-1]!=NULL; i++) {
+ insert=1;
+ if (fields[i]!=NULL) {
+ switch(fields[i][0]) {
+ case 'm': incstr=balsa_app.uname.machine; break;
+ case 'n': incstr=balsa_app.uname.nodename; break;
+ case 'r': incstr=balsa_app.uname.release; break;
+ case 's': incstr=balsa_app.uname.sysname; break;
+ case 'v': incstr=balsa_app.uname.version; break;
+ default: insert=0; break;
+ }
+ } else insert=0;
+ if ((len=strlen(fields[i-1])-previous) > 0) {
+ s=strncpy(s, fields[i-1]+previous, len)+len;
+ }
+ if (insert==1) {
+ s=strncpy(s, incstr, strlen(incstr));
+ s+=strlen(incstr);
+ }
+ previous=insert;
+ }
+ *s=0;
+
+ g_strfreev(fields);
+ return result;
+}
+
+char * get_SystemId_tooltip(char * format)
+{
+ char * tooltip_str;
+ #define TOOLTIPSZ 400
+
+ tooltip_str=(char *)malloc((TOOLTIPSZ+1)*sizeof(char));
+ if (tooltip_str==NULL) return NULL;
+
+ snprintf(tooltip_str, TOOLTIPSZ,
+ "You can use the following sustitutions" \
+ " to describe your system :\n" \
+ "%%m machine type (%s)\n" \
+ "%%h machine's hostname (%s)\n" \
+ "%%s operating system name (%s)\n" \
+ "%%r operating system release (%s)\n" \
+ "%%v operating system version (%s)\n" \
+ ,balsa_app.uname.machine,
+ balsa_app.uname.nodename,
+ balsa_app.uname.sysname,
+ balsa_app.uname.release,
+ balsa_app.uname.version
+ );
+
+ realloc((void *)tooltip_str, (strlen(tooltip_str)+1)*sizeof(char));
+
+ return tooltip_str;
+}
+
+void update_SystemId(void)
+{
+ char *sysid, *tmp;
+
+ sysid=get_SystemId(balsa_app.SystemIdFormat);
+ if (sysid==NULL) return;
+
+ tmp=balsa_app.SystemId;
+ balsa_app.SystemId=sysid;
+ if (tmp) g_free(tmp);
+}
+
diff -u -r -N balsa/src/system-id.h balsa-2/src/system-id.h
--- balsa/src/system-id.h Thu Jan 1 01:00:00 1970
+++ balsa-2/src/system-id.h Tue Aug 28 00:11:46 2001
@@ -0,0 +1,5 @@
+int init_SystemId(void);
+void update_SystemId(void);
+char * get_SystemId_tooltip(char * format);
+char * get_SystemId(char * format);
+
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]