Better mailing list interface... (IMAP header problem.)



I have now tried updating the mailing list handling as discussed earlier; 
I will try to post a usable patch soon, but I need to clean up a bit 
first, and probably also revert some other (unrelated) changes. In the 
mean time, the main section of the code is included below. Note that I 
call this every time current message changes, i.e. the menu is fully 
dynamic.

I have come across one serious obstacle, though: List entries are in many 
cases not found for messages in IMAP mailboxes, as the headers aren't 
necessarily transferred from the server when the menu is built; they 
aren't e.g. when right-clicking on a message that hasn't been viewed yet. 
The old "Reply to Group" function has the same problem, as far as I can 
tell.

Does anyone know a good way around this?
  --
- Toralf

---- [ cut here ] ----


static void balsa_message_list_cb(GtkWidget * widget, gpointer user_data)
{
     const gchar *url=(const gchar *)user_data;

     /* TODO: Share code with handle_url in balsa-message.c */

     if (url && g_strncasecmp(url, "mailto:";, 7)==0) {
	BalsaSendmsg *snd = 	    
sendmsg_window_new(GTK_WIDGET(balsa_app.main_window),
			       NULL, SEND_NORMAL);
	sendmsg_window_process_url(url + 7,
				   sendmsg_window_set_field, snd);
     } else if(url) {
	gnome_url_show(url);
     }
}



static void handle_list_header(GtkWidget *menu, const gchar *id, gchar 
*url) {
     /*** Parts of code taken from  
sendmsg-window.c:set_list_post_rfc2369() */

     while (*(url = rfc2822_skip_comments(url)) == '<') {
	 gchar *close = strchr(++url, '>');
	 	 if (!close)
	     /* broken syntax--break and return FALSE */
	     break;

	 *close='\0';

	 create_stock_menu_item(menu, 				 
(g_strncasecmp(url, "mailto:";, 
7)?GNOME_STOCK_PIXMAP_EXEC:BALSA_PIXMAP_MENU_COMPOSE),
				id, balsa_message_list_cb, url, TRUE);
	 	 if (!(*++close
	       && *(close = rfc2822_skip_comments(close)) == ','))
	     break;
	 url = ++close;
      }
}



void balsa_message_update_list_menu(GtkWidget *widget,
				    LibBalsaMessage *message)
{
     GtkWidget *menu=GTK_MENU_ITEM(widget)->submenu;
     GList *children=gtk_container_children(GTK_CONTAINER(menu)), *child;
     guint cnt=0;
      for(child=children; child; child=g_list_next(child))
	gtk_container_remove(GTK_CONTAINER(menu), GTK_WIDGET(child->data));

     g_list_free(children);

     if(message) {
	gboolean has_post=FALSE;
	GList *hdrs=libbalsa_message_user_hdrs(message), *hdr;
	BalsaIndex *bindex=balsa_find_index_by_mailbox(message->mailbox);


	for(hdr=g_list_first(hdrs); hdr; hdr=g_list_next(hdr)) {
	    gchar **pair=hdr->data;
	    	    if(g_strncasecmp(pair[0], "List-", 5)==0) {
		handle_list_header(menu, pair[0]+5, pair[1]);
		cnt++;
	 
		has_post=(has_post || (g_strcasecmp(pair[0], 
"List-Post")==0));
	    }
	}

	if(has_post) {
	    gtk_menu_append(GTK_MENU(menu), gtk_menu_item_new());
	    create_stock_menu_item(menu, 
BALSA_PIXMAP_MENU_REPLY_GROUP, 				   "Follow-Up", 
balsa_message_replytogroup,
				   bindex, TRUE);
	    cnt++;
	}
     }

     gtk_widget_set_sensitive(widget, (cnt>0));
}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]