New command line attachment patch
- From: "W. Michael Petullo" <mike flyn org>
- To: balsa-list gnome org
- Subject: New command line attachment patch
- Date: Sun, 2 Dec 2001 13:45:16 +0100
Quite some time ago, I submitted a patch to add the ability for a Balsa
user to specify a file to attach to an outgoing message from the command
line. The patch was integrated into the mainstream Balsa source code.
Though the patch was functional, I was not too happy with it; it used
the syntax ``balsa -a attachment_0,attachment_1,'' rather than ``balsa
-a attachment_0 -a attachment_1.'' Gnome_init_with_popt_table() does
not seem to be able to handle the latter syntax.
Enclosed you should find a new patch for 1.2.3, which now uses the
``balsa -a foo -a bar'' syntax. Though I like this method better,
I am still not completely happy with the patch because:
1. Gnome_init_with_popt_table does not handle ``balsa -a foo -a bar''
type arguments directly.
2. Despite (1), If gnome_init is used instead of
gnome_init_with_popt_table, program will complain that ``-a'' is not a
valid option and exit.
3. Since gnome_init_with_popt_table is used, the command line is
parsed twice.
Either I am missing a gnome_init_with_popt_table trick or functionality
clearly has to be added to gnome_init_with_popt_table/gnome_init.
Anyway, please consider my patch. I would enjoy hearing any comments
about gnome_init_with_popt_table.
================================================================================
diff -u --recursive balsa-1.2.3-vanilla/src/balsa-app.h balsa-1.2.3/src/balsa-app.h
--- balsa-1.2.3-vanilla/src/balsa-app.h Sun Nov 4 14:28:37 2001
+++ balsa-1.2.3/src/balsa-app.h Sat Dec 1 22:52:33 2001
@@ -284,7 +284,7 @@
gint open_unread_mailbox;
GList *open_mailbox_list; /* data is a pointer to the mailbox */
gchar *compose_email;
- gchar *attach_file;
+ GSList *attach_file;
/* font used to display messages */
gchar *message_font;
diff -u --recursive balsa-1.2.3-vanilla/src/main.c balsa-1.2.3/src/main.c
--- balsa-1.2.3-vanilla/src/main.c Sat Nov 3 14:02:29 2001
+++ balsa-1.2.3/src/main.c Sat Dec 1 23:49:53 2001
@@ -105,6 +105,9 @@
static void
balsa_init(int argc, char **argv)
{
+ poptContext context;
+ int opt;
+ static char *attachment;
static struct poptOption options[] = {
{"checkmail", 'c', POPT_ARG_NONE,
@@ -112,8 +115,8 @@
N_("Get new mail on startup"), NULL},
{"compose", 'm', POPT_ARG_STRING, &(balsa_app.compose_email),
0, N_("Compose a new email to EMAIL@ADDRESS"), "EMAIL@ADDRESS"},
- {"attach", 'a', POPT_ARG_STRING, &(balsa_app.attach_file),
- 0, N_("Attach file at PATH"), "PATH"},
+ {"attach", 'a', POPT_ARG_STRING, &(attachment),
+ 'a', N_("Attach file at PATH"), "PATH"},
{"open-mailbox", 'o', POPT_ARG_STRING, &(cmd_line_open_mailboxes),
0, N_("Opens MAILBOXNAME"), N_("MAILBOXNAME")},
{"open-unread-mailbox", 'u', POPT_ARG_NONE,
@@ -127,8 +130,23 @@
{NULL, '\0', 0, NULL, 0} /* end the list */
};
- gnome_init_with_popt_table(PACKAGE, VERSION, argc, argv, options, 0,
- NULL);
+ context = poptGetContext(PACKAGE, argc, argv, options, 0);
+ while((opt = poptGetNextOpt(context)) > 0) {
+ switch (opt) {
+ case 'a':
+ balsa_app.attach_file = g_slist_append(balsa_app.attach_file, (void *) attachment);
+ break;
+ }
+ }
+ /* The following is very redundant however:
+ *
+ * 1. gnome_init_with_popt_table does not handle ``balsa -a foo -a
+ * bar'' type arguments, and ``-a foo,bar'' is nasty.
+ *
+ * 2. If gnome_init is used instead, program will complain that
+ * ``-a'' is not a valid option and exit.
+ */
+ gnome_init_with_popt_table(PACKAGE, VERSION, argc, argv, options, 0, NULL);
}
/* check_special_mailboxes:
@@ -347,7 +365,7 @@
gdk_rgb_init();
- if (balsa_app.compose_email || balsa_app.attach_file) {
+ if (balsa_app.compose_email || g_slist_length(balsa_app.attach_file)) {
BalsaSendmsg *snd;
snd = sendmsg_window_new(window, NULL, SEND_NORMAL);
if(balsa_app.compose_email) {
@@ -356,20 +374,13 @@
sendmsg_window_set_field, snd);
else sendmsg_window_set_field(snd,"to", balsa_app.compose_email);
}
- if (balsa_app.attach_file) {
- gchar *ptr = balsa_app.attach_file;
- gchar *delim;
- gchar *attachment;
- while ((delim = strchr (ptr, ','))) {
- *delim = '\0';
- attachment = g_strdup(ptr);
- add_attachment(GNOME_ICON_LIST(snd->attachments[1]),
- attachment, FALSE, NULL);
- ptr = delim + 1;
- }
- attachment = g_strdup(ptr);
- add_attachment(GNOME_ICON_LIST(snd->attachments[1]), attachment,
- FALSE, NULL);
+ if (g_slist_length(balsa_app.attach_file)) {
+ GSList *attachment;
+ attachment = balsa_app.attach_file;
+ do {
+ add_attachment(GNOME_ICON_LIST(snd->attachments[1]),
+ attachment->data, FALSE, NULL);
+ } while(attachment = g_slist_next(attachment));
}
} else
gtk_widget_show(window);
@@ -467,6 +478,7 @@
balsa_app.mailbox_nodes = NULL;
gnome_sound_shutdown();
libbalsa_imap_close_all_connections();
+ g_slist_free(balsa_app.attach_file);
if(balsa_app.debug) g_print("Finished cleaning up.\n");
}
================================================================================
--
Mike
:wq
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]