⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 netfolders.c

📁 一个功能全面的电子邮件客户端
💻 C
📖 第 1 页 / 共 2 页
字号:
/* TradeClient <http://tradeclient.sourceforge.net> * $Id: netfolders.c,v 1.5 2001/03/20 22:19:33 ttabner Exp $ * * Copyright (C) 1999-2000 Bynari Inc. * Copyright (C) 2001 Project TradeClient * * LGPL * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Library 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 Library * General Public License for more details. * * You should have received a copy of the GNU Library 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 "netfolders.h"#ifdef DEBUG# define MAIL_OP OP_DEBUG#else# define MAIL_OP 0#endifGList *nf_imap_list = NULL;GList *nf_imap_folder_list = NULL;GList *nf_imap_lsub = NULL;GList *nf_imap_unseen = NULL;GList *nf_imap_lsub_play = NULL;intnf_add_imap_acct (PopAccount * acct){  ImapInfo *imapinfo = (ImapInfo *) calloc (1, sizeof (ImapInfo));  char *data[3];  imapinfo->acct = acct;  imapinfo->tree = lookup_widget (tm_globs->main_window, "folder_ntree");  imapinfo->parent = NULL;  imapinfo->lsub = 0;  imapinfo->mailbox = NULL;  if (!acct)    return 1;  /* insert the node to the tree */  data[0] = strdup (acct->name);  data[1] = strdup ("-");  data[2] = strdup ("-");  imapinfo->node =    (GtkWidget *) gtk_ctree_insert_node (GTK_CTREE (imapinfo->tree), NULL,					 NULL, data, 0, NULL, NULL, NULL,					 NULL, FALSE, FALSE);  free (data[0]);  free (data[1]);  free (data[2]);  if (!imapinfo->node)    return 1;  gtk_ctree_node_set_row_data (GTK_CTREE (imapinfo->tree),			       GTK_CTREE_NODE (imapinfo->node),			       (gpointer) imapinfo);  nf_imap_list = g_list_append (nf_imap_list, imapinfo);  return 0;}intnf_imap_folder_sel2 (GtkWidget * widget, GdkEventButton * event,		     gpointer data){  GtkCTree *ctree = GTK_CTREE (widget);  GtkWidget *popmenu;  ImapInfo *imapinfo;  char *mailbox = NULL;  char *list = NULL;  GList *boxes;  char *box;  ImapInfo *tmpimap;  char *open;  GtkWidget *win;  int popup = 0;  int row, col;  GtkCTreeNode *node;  if (tm_globs->imap_window)    {      gdk_window_raise (tm_globs->imap_window->window);      return 3;    }  gtk_clist_get_selection_info (GTK_CLIST (ctree), event->x, event->y,				&row, &col);  node = GTK_CTREE_NODE (g_list_nth (GTK_CLIST (ctree)->row_list, row));  if (event->button != 1)    {      if (event->button == 3)	{	  popmenu = nf_imapf_popup_menu ();	  gtk_menu_popup (GTK_MENU (popmenu), NULL, NULL, NULL, NULL, 3, 0);	}      else	{	  if (event->button == 2)	    {	      if ((ctree)&&(node))                {	      gtk_ctree_select (ctree, node);	      popup = 1;	    }	}	}      if (!popup)	return 1;    }  if (event->type == 5)    popup = 1;  tm_globs->imap_node = (GtkWidget *) node;  imapinfo = gtk_ctree_node_get_row_data (ctree, GTK_CTREE_NODE (node));  if ((!imapinfo) || (!imapinfo->acct))    return 1;  mailbox = (char *) calloc (4096, sizeof (char));  snprintf (mailbox, 4094, "{%s:%d/imap/user=\"%s\"}%s",	    imapinfo->acct->phost, imapinfo->acct->pport,	    imapinfo->acct->puser, "INBOX");  if ((tm_globs->mailstream) && (mmpopid == imapinfo->acct->id))    {      mmpopid = imapinfo->acct->id;      mail_ping (tm_globs->mailstream);      if (imapinfo->mailbox)	{	  mail_status (tm_globs->mailstream, imapinfo->mailbox,		       SA_UNSEEN | SA_MESSAGES);	}      else	{	  mail_status (tm_globs->mailstream, mailbox,		       SA_UNSEEN | SA_MESSAGES);	}    }  else    {      mmpopid = imapinfo->acct->id;      /* open new mailstream */      tm_globs->mailstream = mail_open (tm_globs->mailstream, mailbox,					OP_HALFOPEN | MAIL_OP);      if (!imapinfo->mailbox)	mail_status (tm_globs->mailstream, mailbox, SA_UNSEEN | SA_MESSAGES);      if (!tm_globs->mailstream)	return 3;    }  /* find all boxes */  nf_imap_lsub = NULL;  list = (char *) calloc (4096, sizeof (char));  snprintf (list, 4094, "{%s:%d/imap/user=\"%s\"}*", imapinfo->acct->phost,	    imapinfo->acct->pport, imapinfo->acct->puser);  if (imapinfo->parent == NULL)    {      mail_lsub (tm_globs->mailstream, NULL, list);      imapinfo->lsub = 1;    }  if (list)    free (list);  /* update counts for each */  if (nf_imap_lsub)    {      for (boxes = nf_imap_lsub; boxes; boxes = boxes->next)	{	  tmpimap = (ImapInfo *) boxes->data;	  box = tmpimap->mailbox;	  tm_globs->imap_node = tmpimap->node;	  mail_status (tm_globs->mailstream, box, SA_UNSEEN | SA_MESSAGES);	}    }  if (popup)    {      if (imapinfo->mailbox)	{	  open = imapinfo->mailbox;	}      else	{	  open = mailbox;	}      if (tm_globs->imap_window)	{	  insert_warning	    ("Please close the existing IMAP window before opening another.\n");	}      else	{	  win = create_imap_window (imapinfo->acct, open, imapinfo);	  tm_globs->imap_window = win;	  /* fill up the imap win!!! */	  gtk_widget_show (win);	  nf_imap_fill_up (win, imapinfo->acct, open);	}    }  free (mailbox);  return 0;}intnf_imap_folder_sel (GtkCTree * ctree, GList * node, gint column,		    gpointer user_data){  gtk_ctree_unselect_recursive (ctree, GTK_CTREE_NODE (node));  return 0;}intnf_imap_handle_counts (GtkCTreeNode * node, int unseen, int total){  char *ucount, *tcount;  GtkWidget *widget = lookup_widget (tm_globs->main_window, "folder_ntree");  ImapInfo *imapinfo;  char *open, *mbox, *tmp;  imapinfo = gtk_ctree_node_get_row_data (GTK_CTREE (widget), node);  if (!imapinfo->acct)    return 1;  ucount = (char *) calloc (5, sizeof (char));  tcount = (char *) calloc (5, sizeof (char));  snprintf (ucount, 5, "%d", unseen);  snprintf (tcount, 5, "%d", total);  gtk_ctree_node_set_text (GTK_CTREE (widget), node, 1, ucount);  gtk_ctree_node_set_text (GTK_CTREE (widget), node, 2, tcount);  free (ucount);  free (tcount);  if (tm_globs->imap_window) {    if (imapinfo->mailbox) {      tmp = strdup (imapinfo->mailbox);    } else {      tmp = (char *) calloc (4096, sizeof (char));      snprintf (tmp, 4094, "{%s:%d/imap/user=\"%s\"}%s",                imapinfo->acct->phost, imapinfo->acct->pport,                imapinfo->acct->puser, "INBOX");    }    mbox = cut_string (tmp, '}', 2, 1);    open = (char *) malloc (1024 * sizeof (char));    snprintf (open, 1024, "IMAP - %s:%s", imapinfo->acct->name, mbox);    if (strcmp (GTK_WINDOW (tm_globs->imap_window)->title, open) == 0) {      tm_globs->imap_tmp = imapinfo;    }    if (tmp) free (tmp);    if (open) free (open);    if (mbox) free (mbox);  }  return 0;}intnf_imap_handle_list (GtkCTreeNode * node, char *box){	GtkWidget *ctree = tm_globs->imap_list;	ImapInfo *imapinfo, *newimapinfo;	char *data[1];	imapinfo = gtk_ctree_node_get_row_data (GTK_CTREE (ctree), node);	newimapinfo = (ImapInfo *) calloc (1, sizeof (ImapInfo));	newimapinfo->acct = imapinfo->acct;	newimapinfo->tree = ctree;	newimapinfo->parent = (GtkWidget *)node;	newimapinfo->mailbox = strdup (box);	data[0] = strdup (box);	newimapinfo->node =		(GtkWidget *) gtk_ctree_insert_node (GTK_CTREE (ctree), node,                                         NULL, data, 0, NULL, NULL, NULL,                                         NULL, FALSE, FALSE);	gtk_ctree_node_set_row_data (GTK_CTREE (imapinfo->tree),                               GTK_CTREE_NODE (newimapinfo->node),                               (gpointer) newimapinfo);  return 0;}intnf_imap_handle_folders (GtkCTreeNode * node, char *box){  GtkWidget *widget = lookup_widget (tm_globs->main_window, "folder_ntree");  ImapInfo *imapinfo, *newimapinfo;  char *data[3];  char *mailbox;  GList *seek = NULL;  char *tmpbox;  imapinfo = gtk_ctree_node_get_row_data (GTK_CTREE (widget), node);  newimapinfo = (ImapInfo *) calloc (1, sizeof (ImapInfo));  newimapinfo->acct = imapinfo->acct;  newimapinfo->tree = imapinfo->tree;  newimapinfo->parent = imapinfo->node;  mailbox = (char *) calloc (4096, sizeof (char));  snprintf (mailbox, 4094, "{%s:%d/imap/user=\"%s\"}%s",	    newimapinfo->acct->phost, newimapinfo->acct->pport,	    newimapinfo->acct->puser, box);  newimapinfo->mailbox = mailbox;  for (seek = nf_imap_folder_list; seek; seek = seek->next)    {      tmpbox = seek->data;      if (!strcmp (tmpbox, newimapinfo->mailbox))	{	  free (mailbox);	  return 1;	}    }  nf_imap_lsub = g_list_append (nf_imap_lsub, newimapinfo);  data[0] = strdup (box);  data[1] = strdup ("-");  data[2] = strdup ("-");  newimapinfo->node =    (GtkWidget *) gtk_ctree_insert_node (GTK_CTREE (imapinfo->tree),					 GTK_CTREE_NODE (imapinfo->node),					 NULL, data, 0, NULL, NULL, NULL,					 NULL, FALSE, FALSE);  gtk_ctree_node_set_row_data (GTK_CTREE (imapinfo->tree),			       GTK_CTREE_NODE (newimapinfo->node),			       (gpointer) newimapinfo);  nf_imap_folder_list = g_list_append (nf_imap_folder_list, mailbox);  free (data[0]);  free (data[1]);  free (data[2]);  return 0;}intnf_imap_fill_up (GtkWidget * win, PopAccount * acct, char *mailbox){  GtkWidget *clist = lookup_widget (win, "imap_clist");  Header_Info *hinfo = NULL;  char *header;  int count, total;  char *data[3];  ImapMsg *imapmsg;  int row;  GList *unseen;  SEARCHPGM *pgm = mail_newsearchpgm ();  GtkStyle *unread, *read;  tm_globs->mailstream = mail_open (tm_globs->mailstream, mailbox, MAIL_OP);  if (!tm_globs->mailstream)    return 1;  gtk_clist_freeze (GTK_CLIST (clist));  gtk_clist_clear (GTK_CLIST (clist));  g_list_free (nf_imap_unseen);  nf_imap_unseen = NULL;  pgm->unseen = 1;  mail_search_full (tm_globs->mailstream, NULL, pgm, 0);  unread = gtk_style_copy (clist->style);  read = gtk_style_copy (clist->style);  unread->font = gdk_font_load ("-*-helvetica-bold-r-*--*-*-*-*-*-*-*-1");  read->font = gdk_font_load ("-*-helvetica-medium-r-*--*-*-*-*-*-*-*-1");  total = tm_globs->mailstream->nmsgs;  for (count = 1; count <= total; count++)    {      header = NULL;      header = mail_fetchheader (tm_globs->mailstream, count);      if (!header)	break;      hinfo = parse_header (header);      data[0] = strdup (hinfo->subject ? hinfo->subject : "");      data[1] = strdup (hinfo->from ? hinfo->from : "");      data[2] = strdup (hinfo->date ? hinfo->date : "");      destroy_hinfo (hinfo);      //free (hinfo);      row = gtk_clist_prepend (GTK_CLIST (clist), data);      free (data[0]);      free (data[1]);      free (data[2]);      imapmsg = (ImapMsg *) calloc (1, sizeof (ImapMsg));      imapmsg->acct = acct;      imapmsg->mailbox = mailbox;      imapmsg->msgno = count;      gtk_clist_set_row_data (GTK_CLIST (clist), row, (gpointer) imapmsg);      unseen = g_list_find (nf_imap_unseen, (gpointer) count);      if (unseen)	{	  gtk_clist_set_row_style (GTK_CLIST (clist), row, unread);	}      else	{	  gtk_clist_set_row_style (GTK_CLIST (clist), row, read);	}    }  gtk_clist_thaw (GTK_CLIST (clist));  return 0;}GtkWidget *nf_imapf_popup_menu (){

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -