--- /dev/null
+/*
+ * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
+ * Copyright (C) 1999-2002 Hiroyuki Yamamoto
+ *
+ * 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 of the License, 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.
+ */
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <glib.h>
+#include <gdk/gdkkeysyms.h>
+#include <gtk/gtkwidget.h>
+#include <gtk/gtkwindow.h>
+#include <gtk/gtksignal.h>
+#include <gtk/gtkscrolledwindow.h>
+#include <gtk/gtktext.h>
+#include <gtk/gtkstyle.h>
+
+#include "intl.h"
+#include "logwindow.h"
+#include "utils.h"
+#include "gtkutils.h"
+#include "log.h"
+#include "hooks.h"
+
+static void hide_cb (GtkWidget *widget,
+ LogWindow *logwin);
+static void key_pressed (GtkWidget *widget,
+ GdkEventKey *event,
+ LogWindow *logwin);
+static gboolean log_window_append (gpointer source,
+ gpointer data);
+static void log_window_clip (GtkWidget *text,
+ guint glip_length);
+
+LogWindow *log_window_create(void)
+{
+ LogWindow *logwin;
+ GtkWidget *window;
+ GtkWidget *scrolledwin;
+ GtkWidget *text;
+
+ debug_print("Creating log window...\n");
+ logwin = g_new0(LogWindow, 1);
+
+ window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+ gtk_window_set_title(GTK_WINDOW(window), _("Protocol log"));
+ gtk_window_set_wmclass(GTK_WINDOW(window), "log_window", "Sylpheed");
+ gtk_window_set_policy(GTK_WINDOW(window), TRUE, TRUE, FALSE);
+ gtk_widget_set_usize(window, 520, 400);
+ gtk_signal_connect(GTK_OBJECT(window), "delete_event",
+ GTK_SIGNAL_FUNC(gtk_widget_hide_on_delete), NULL);
+ gtk_signal_connect(GTK_OBJECT(window), "key_press_event",
+ GTK_SIGNAL_FUNC(key_pressed), logwin);
+ gtk_signal_connect(GTK_OBJECT(window), "hide",
+ GTK_SIGNAL_FUNC(hide_cb), logwin);
+ gtk_widget_realize(window);
+
+ scrolledwin = gtk_scrolled_window_new(NULL, NULL);
+ gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
+ GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
+ gtk_container_add(GTK_CONTAINER(window), scrolledwin);
+ gtk_widget_show(scrolledwin);
+
+ text = gtk_text_new(gtk_scrolled_window_get_hadjustment
+ (GTK_SCROLLED_WINDOW(scrolledwin)),
+ gtk_scrolled_window_get_vadjustment
+ (GTK_SCROLLED_WINDOW(scrolledwin)));
+ gtk_container_add(GTK_CONTAINER(scrolledwin), text);
+ gtk_widget_show(text);
+ gtk_text_freeze(GTK_TEXT(text));
+
+ logwin->window = window;
+ logwin->scrolledwin = scrolledwin;
+ logwin->text = text;
+ logwin->hook_id = hooks_register_hook(LOG_APPEND_TEXT_HOOKLIST, log_window_append, logwin);
+
+ return logwin;
+}
+
+void log_window_init(LogWindow *logwin)
+{
+ GdkColormap *colormap;
+ GdkColor color[3] =
+ {{0, 0, 0xafff, 0}, {0, 0xefff, 0, 0}, {0, 0xefff, 0, 0}};
+ gboolean success[3];
+ gint i;
+
+ gtkut_widget_disable_theme_engine(logwin->text);
+
+ logwin->msg_color = color[0];
+ logwin->warn_color = color[1];
+ logwin->error_color = color[2];
+
+ colormap = gdk_window_get_colormap(logwin->window->window);
+ gdk_colormap_alloc_colors(colormap, color, 3, FALSE, TRUE, success);
+
+ for (i = 0; i < 3; i++) {
+ if (success[i] == FALSE) {
+ GtkStyle *style;
+
+ g_warning("LogWindow: color allocation failed\n");
+ style = gtk_widget_get_style(logwin->window);
+ logwin->msg_color = logwin->warn_color =
+ logwin->error_color = style->black;
+ break;
+ }
+ }
+}
+
+void log_window_show(LogWindow *logwin)
+{
+ GtkText *text = GTK_TEXT(logwin->text);
+
+ gtk_widget_hide(logwin->window);
+
+ gtk_text_thaw(text);
+ text->vadj->value = text->vadj->upper - text->vadj->page_size;
+ gtk_signal_emit_by_name(GTK_OBJECT(text->vadj), "value_changed");
+
+ gtk_widget_show(logwin->window);
+}
+
+void log_window_set_clipping(LogWindow *logwin, gboolean clip, guint clip_length)
+{
+ g_return_if_fail(logwin != NULL);
+
+ logwin->clip = clip;
+ logwin->clip_length = clip_length;
+}
+
+static gboolean log_window_append(gpointer source, gpointer data)
+{
+ LogText *logtext = (LogText *) source;
+ LogWindow *logwindow = (LogWindow *) data;
+ GtkText *text;
+ GdkColor *color = NULL;
+ gchar *head = NULL;
+
+ g_return_val_if_fail(logtext != NULL, TRUE);
+ g_return_val_if_fail(logtext->text != NULL, TRUE);
+ g_return_val_if_fail(logwindow != NULL, FALSE);
+
+ if (logwindow->clip && !logwindow->clip_length)
+ return FALSE;
+
+ text = GTK_TEXT(logwindow->text);
+
+ switch (logtext->type) {
+ case LOG_MSG:
+ color = &logwindow->msg_color;
+ head = "* ";
+ break;
+ case LOG_WARN:
+ color = &logwindow->warn_color;
+ head = "** ";
+ break;
+ case LOG_ERROR:
+ color = &logwindow->error_color;
+ head = "*** ";
+ break;
+ default:
+ break;
+ }
+
+ if (head) gtk_text_insert(text, NULL, color, NULL, head, -1);
+ gtk_text_insert(text, NULL, color, NULL, logtext->text, -1);
+ if (logwindow->clip)
+ log_window_clip (GTK_WIDGET (text), logwindow->clip_length);
+
+ return FALSE;
+}
+
+static void hide_cb(GtkWidget *widget, LogWindow *logwin)
+{
+ if (GTK_TEXT(logwin->text)->freeze_count == 0)
+ gtk_text_freeze(GTK_TEXT(logwin->text));
+}
+
+static void key_pressed(GtkWidget *widget, GdkEventKey *event,
+ LogWindow *logwin)
+{
+ if (event && event->keyval == GDK_Escape)
+ gtk_widget_hide(logwin->window);
+}
+
+static void log_window_clip(GtkWidget *textw, guint clip_length)
+{
+ guint length;
+ guint point;
+ gboolean was_frozen = FALSE;
+ GtkText *text = GTK_TEXT(textw);
+
+ length = gtk_text_get_length (text);
+ debug_print("Log window length: %u\n", length);
+
+ if (length > clip_length) {
+ /* find the end of the first line after the cut off
+ * point */
+ point = length - clip_length;
+ while (point < length && GTK_TEXT_INDEX(text, point) != '\n')
+ point++;
+ /* erase the text */
+ if (text->freeze_count) {
+ was_frozen = TRUE;
+ gtk_text_thaw(text);
+ }
+ gtk_text_set_point (text, 0);
+ gtk_text_freeze(text);
+ if (!gtk_text_forward_delete (text, point + 1))
+ debug_print("Error clearing log\n");
+ gtk_text_thaw(text);
+ gtk_text_set_point(text,
+ gtk_text_get_length (GTK_TEXT (text)));
+ if (was_frozen)
+ gtk_text_freeze(text);
+ }
+}
--- /dev/null
+/*
+ * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
+ * Copyright (C) 1999,2000 Hiroyuki Yamamoto
+ *
+ * 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 of the License, 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.
+ */
+
+#ifndef __LOGWINDOW_H__
+#define __LOGWINDOW_H__
+
+#include <glib.h>
+#include <gtk/gtkwidget.h>
+
+typedef struct _LogWindow LogWindow;
+
+struct _LogWindow
+{
+ GtkWidget *window;
+ GtkWidget *scrolledwin;
+ GtkWidget *text;
+
+ GdkColor msg_color;
+ GdkColor warn_color;
+ GdkColor error_color;
+
+ gboolean clip;
+ guint clip_length;
+ guint hook_id;
+};
+
+LogWindow *log_window_create(void);
+void log_window_init(LogWindow *logwin);
+void log_window_show(LogWindow *logwin);
+void log_window_set_clipping(LogWindow *logwin, gboolean clip, guint clip_length);
+
+#endif /* __LOGWINDOW_H__ */
--- /dev/null
+/*
+ * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
+ * Copyright (C) 2003 Hiroyuki Yamamoto & the Sylpheed-Claws team
+ *
+ * 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 of the License, 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.
+ */
+
+#ifndef PREFS_FONTS_H
+#define PREFS_FONTS_H
+
+void prefs_fonts_init (void);
+void prefs_fonts_done (void);
+
+#endif /* PREFS_FONTS_H */
--- /dev/null
+#!/usr/bin/python2.2
+"""
+
+Copyright © 2003 Bogdan Sumanariu <zarrok@yahoo.com>
+
+ This file 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 of the License, 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.
+
+ script name : evolutionvcard2sylpheed.py
+
+ script purpose : convert an evolution addressbook VCARD file
+ into a Sylpheed addressbook
+
+ tested with evolution 1.2.x, and 1.4.x
+
+"""
+
+import string
+import sys
+import time
+import os
+
+keywds = ('x-evolution-file-as','fn', 'n','email;internet','nickname', 'url', 'org')
+
+
+################################################################################
+## reads a vcard and stores as hash pairs key/value where value is a list ##
+################################################################################
+
+def readVCARD (file) :
+
+ """
+
+ skips fom <file> until a 'begin' tag from VCARD is encountered.
+ from this point starts constructing a map (key, [values] )
+ VCARD entry format -> tag:value
+
+ key <- tag
+ [values] <- list with the values of <tag> if there are more tags with the same name
+
+ """
+ r=' '
+ bgn,end = -1, -1;
+ d = dict()
+ while r and bgn < 0 :
+ r = file.readline()
+ if len (r) == 0 : return dict()
+ if string.find('begin',string.lower(string.strip(r))) :
+ bgn = 1
+ while r and end < 0 :
+ r = file.readline()
+ s = string.split(string.lower(string.strip(r)),':')
+ if s[0] <> '' :
+ if d.has_key(s[0]) :
+ d[s[0]].append(s[1])
+ elif len(s) > 1:
+ d[s[0]] = [s[1]]
+ else :
+ d[s[0]] = ['']
+ if s[0] == 'end' : end = 1
+ return d
+
+##################################################################################
+
+
+###############################################################################################
+## writes on a given file an xml representation for sylpheed addressbook received as a hash ##
+###############################################################################################
+
+def writeXMLREPR (vcard,file,uid) :
+
+ """
+ based on <vcard> and <uid> writes only recognized tags (the ones defined in <keywds> list)
+ NOTE: <url> and <org> tag will be written as attributes (there are such tags in sylpheed's
+ XML schema)
+ """
+ if len (vcard.keys()) == 0 : return
+ name = string.split(vcard.get(keywds[2])[0],';')
+
+ fn, ln, nick, cn, a = '', '', '', '', ''
+
+ if len(name) == 2 :
+ fn = name[0]
+ ln = name[1]
+ elif len(name) ==1 :
+ fn = name[0]
+
+ if vcard.has_key(keywds[4]) :
+ nick = vcard.get(keywds[4])[0]
+ if len(vcard.get(keywds[1])[0]) :
+ cn = vcard.get(keywds[1])[0]
+ else :
+ cn = vcard.get(keywds[0])[0];
+
+ a += str('\n<person uid=\"' + str(uid[0]) + '\" first-name=\"' + fn + '\" last-name=\"' + ln
+ + '\" nick-name=\"' + nick + '\" cn=\"' + cn + '\" >\n')
+ a += '\t<address-list>\n'
+ if vcard.get(keywds[3]) :
+ for c in vcard.get(keywds[3]) :
+ uid[0] = uid[0] + 1
+ a += '\t\t<address uid=\"' + str(uid[0]) + '\" alias=\"' + nick + '\" email=\"' + c + '\" remarks=\"\" />\n'
+ else :
+ uid[0] = uid[0]+1
+ a += '\t\t<address uid=\"' + str(uid[0]) + '\" alias=\"' + nick + '\" email=\"\" remarks=\"\" />\n'
+ a += '\t</address-list>\n'
+ a += '\t<attribute-list>\n'
+ for key in keywds[5:] :
+ if vcard.get(key) :
+ for c in vcard.get(key) :
+ uid[0] = uid[0] + 1
+ a += '\t\t<attribute uid=\"' + str(uid[0]) + '\" name=\"' + key +'\">'+c+'</attribute>\n'
+ a += '\t</attribute-list>\n'
+ a += '</person>\n'
+ file.write(a)
+ file.flush()
+
+###################################################################################################
+
+def convert (in_f, o_f, name='INBOX') :
+ d = {'d':1}
+ uid = [int(time.time())]
+ try :
+ print 'proccessing...\n'
+ o_f.write('<?xml version="1.0" encoding="ISO-8859-1" ?>\n<address-book name="'+name+'" >\n');
+
+ while len(d.keys()) > 0 :
+ d = readVCARD(in_f)
+ writeXMLREPR (d, o_f, uid)
+ uid[0] = uid [0]+1
+
+ o_f.write('\n</address-book>')
+ print 'finished processing...\n'
+ except IOError, err :
+ print 'Caught an IOError : ',err,'\t ABORTING!!!'
+ raise err
+
+#################################################################################################
+
+def execute () :
+ if len(sys.argv) <> 3 and len(sys.argv) <> 2 :
+ print str("\nUsage: vcard2xml.py source_file [destination_file]\n\n" +
+ '\tWhen only <source_file> is specified will overwrite the existing addressbook.\n'+
+ '\tWhen both arguments are suplied will create a new additional addressbook named \n\tas the destination file.'+'\n\tNOTE: in both cases the sylpheed must be closed and ran at least once.\n\n')
+ sys.exit(1)
+
+ in_file = None
+ out_file = None
+ path_to_out = os.environ['HOME']+'/.sylpheed/'
+ adr_idx = 'addrbook--index.xml'
+ adr_idx_file = None
+ tmp_adr_idx_file= None
+ got_ex = 0
+
+ try :
+ in_file = open(sys.argv[1])
+ except IOError, e:
+ print 'Could not open input file <',sys.argv[1],'> ABORTING'
+ sys.exit(1)
+
+ if len(sys.argv) == 2 :
+ try :
+ dlist = os.listdir(path_to_out);
+ flist=[]
+ for l in dlist :
+ if l.find('addrbook') == 0 and l.find("addrbook--index.xml") < 0 and l.find('bak') < 0 :
+ flist.append(l)
+ flist.sort()
+ out_file = flist.pop()
+ os.rename(path_to_out+out_file, path_to_out+out_file+'.tmp')
+ out_file = open(path_to_out+out_file,'w')
+ convert(in_file, out_file)
+ except Exception, e:
+ got_ex = 1
+ print 'got exception: ', e
+ else :
+ try :
+ os.rename(path_to_out+adr_idx, path_to_out+adr_idx+'.tmp')
+ tmp_adr_idx_file = open(path_to_out+adr_idx+'.tmp')
+ adr_idx_file = open(path_to_out+adr_idx,'w')
+ except Exception, e :
+ print 'Could not open <', path_to_out+adr_idx,'> file. Make sure you started sylpheed at least once.'
+ sys.exit(1)
+ try :
+ out_file = open(path_to_out+sys.argv[2],'w')
+ convert(in_file, out_file, sys.argv[2].split('.xml')[0])
+ l = tmp_adr_idx_file.readline()
+ while l :
+ if l.strip() == '</book_list>' :
+ adr_idx_file.write('\t<book name="'+sys.argv[2].split('.xml')[0] +'" file="'+sys.argv[2]+'" />\n')
+ adr_idx_file.write(l)
+ else :
+ adr_idx_file.write(l)
+ l = tmp_adr_idx_file.readline()
+ except Exception, e:
+ got_ex = 1
+ print 'got exception: ', e
+
+
+ if got_ex :
+ #clean up the mess
+ print 'got exception, cleaning up the mess... changed files will be restored...\n'
+ if adr_idx_file :
+ adr_idx_file.close()
+ if out_file :
+ out_file.close()
+ if len(sys.argv) == 2 :
+ os.rename(out_file.name+'.tmp', out_file.name)
+ else :
+ os.remove(out_file.name)
+ os.rename(path_to_out+adr_idx+'.tmp', path_to_out+adr_idx)
+ if tmp_adr_idx_file :
+ tmp_adr_idx_file.close()
+
+ else :
+ #closing all and moving temporary data into place
+ print 'closing open files...\n'
+ in_file.close()
+ out_file.close()
+ if len(sys.argv) == 3 :
+ os.rename(path_to_out+adr_idx+'.tmp',path_to_out+adr_idx+'.bak' )
+ if len(sys.argv) == 2 :
+ os.rename(out_file.name+'.tmp', out_file.name+'.bak')
+ if adr_idx_file :
+ adr_idx_file.close()
+ if tmp_adr_idx_file :
+ tmp_adr_idx_file.close()
+ print 'done!'
+
+
+if __name__ == '__main__':
+ execute ()
+
+