Пример #1
0
void notification_trayicon_msg(MsgInfo *msginfo)
{
#ifndef HAVE_LIBNOTIFY
  return;

#else
  FolderType ftype;
  NotificationFolderType nftype;
  gchar *uistr;

  nftype = F_TYPE_MAIL;

  if(!msginfo || !notify_config.trayicon_enabled ||
     !notify_config.trayicon_popup_enabled ||
     !MSG_IS_NEW(msginfo->flags))
    return;

  if(notify_config.trayicon_folder_specific) {
    guint id;
    GSList *list;
    gchar *identifier;
    gboolean found = FALSE;

    if(!(msginfo->folder))
      return;

    identifier = folder_item_get_identifier(msginfo->folder);

    id =
      notification_register_folder_specific_list
      (TRAYICON_SPECIFIC_FOLDER_ID_STR);
    list = notification_foldercheck_get_list(id);
    for(; (list != NULL) && !found; list = g_slist_next(list)) {
      gchar *list_identifier;
      FolderItem *list_item = (FolderItem*) list->data;

      list_identifier = folder_item_get_identifier(list_item);
      if(!strcmp2(list_identifier, identifier))
	found = TRUE;

      g_free(list_identifier);
    }
    g_free(identifier);

    if(!found)
      return;
  } /* folder specific */

  ftype = msginfo->folder->folder->klass->type;

  G_LOCK(trayicon_popup);
  /* Check out which type to notify about */
  switch(ftype) {
  case F_MH:
  case F_MBOX:
  case F_MAILDIR:
  case F_IMAP:
    nftype = F_TYPE_MAIL;
    break;
  case F_NEWS:
    nftype = F_TYPE_NEWS;
    break;
  case F_UNKNOWN:
    if((uistr = msginfo->folder->folder->klass->uistr) == NULL) {
      G_UNLOCK(trayicon_popup);
      return;
    }
    else if(!strcmp(uistr, "vCalendar"))
      nftype = F_TYPE_CALENDAR;
    else if(!strcmp(uistr, "RSSyl"))
      nftype = F_TYPE_RSS;
    else {
      debug_print("Notification Plugin: Unknown folder type %d\n",ftype);
      G_UNLOCK(trayicon_popup);
      return;
    }
    break;
  default:
    debug_print("Notification Plugin: Unknown folder type %d\n",ftype);
    G_UNLOCK(trayicon_popup);
    return;
  }


  notification_trayicon_popup_add_msg(msginfo, nftype);

  G_UNLOCK(trayicon_popup);

#endif /* HAVE_LIBNOTIFY */
}
Пример #2
0
static void mh_write_sequences(FolderItem *item, gboolean remove_unseen)
{
	gchar *mh_sequences_old, *mh_sequences_new;
	FILE *mh_sequences_old_fp, *mh_sequences_new_fp;
	gchar buf[BUFFSIZE];
	gchar *path = NULL;
	gboolean err = FALSE;
	START_TIMING("");

	if (!item)
		return;
	
	path = folder_item_get_path(item);

	mh_sequences_old = g_strconcat(path, G_DIR_SEPARATOR_S,
					    ".mh_sequences", NULL);
	mh_sequences_new = g_strconcat(path, G_DIR_SEPARATOR_S,
					    ".mh_sequences.new", NULL);
	if ((mh_sequences_new_fp = g_fopen(mh_sequences_new, "w+b")) != NULL) {
		GSList *msglist = folder_item_get_msg_list(item);
		GSList *cur;
		MsgInfo *info = NULL;
		gint start = -1, end = -1;
		gchar *sequence = g_strdup("");
		gint seq_len = 0;
		msglist = g_slist_sort(msglist, sort_cache_list_by_msgnum);
		cur = msglist;
		
		/* write the unseen sequence if we don't have to scrap it */
		if (!remove_unseen) do {
			info = (MsgInfo *)(cur ? cur->data:NULL);
			if (info && (MSG_IS_UNREAD(info->flags) || MSG_IS_NEW(info->flags))) {
				if (start < 0)
					start = end = info->msgnum;
				else
					end = info->msgnum;
			} else {
				if (start > 0 && end > 0) {
					gchar tmp[32];
					gint tmp_len = 0;
					if (start != end)
						snprintf(tmp, 31, " %d-%d", start, end);
					else
						snprintf(tmp, 31, " %d", start);
					
					tmp_len = strlen(tmp);
					sequence = g_realloc(sequence, seq_len+tmp_len+1);
					strcpy(sequence+seq_len, tmp);
					seq_len += tmp_len;

					start = end = -1;
				}
			}
			cur = cur ? cur->next:NULL;
		} while (cur || (start > 0 && end > 0));
		if (sequence && *sequence) {
			if (fprintf(mh_sequences_new_fp, "%s%s\n", 
					get_unseen_seq_name(), sequence) < 0)
				err = TRUE;
			else
				debug_print("wrote unseen sequence: '%s%s'\n", 
					get_unseen_seq_name(), sequence);
		}
		/* rewrite the rest of the file */
		if ((mh_sequences_old_fp = g_fopen(mh_sequences_old, "r+b")) != NULL) {
			while (fgets(buf, sizeof(buf), mh_sequences_old_fp) != NULL) {
				if (strncmp(buf, get_unseen_seq_name(), strlen(get_unseen_seq_name())))
					if (fprintf(mh_sequences_new_fp, "%s", buf) < 0) {
						err = TRUE;
						break;
					}
			}
			fclose(mh_sequences_old_fp);
		}
		
		fflush(mh_sequences_new_fp);
#if 0
		fsync(fileno(mh_sequences_new_fp));
#endif
		if (fclose(mh_sequences_new_fp) == EOF)
			err = TRUE;

		if (!err) {
			if (g_rename(mh_sequences_new, mh_sequences_old) < 0)
				FILE_OP_ERROR(mh_sequences_new, "rename");
		}
		g_free(sequence);
		procmsg_msg_list_free(msglist);
	}
	g_free(mh_sequences_old);
	g_free(mh_sequences_new);
	g_free(path);

	END_TIMING();
}
Пример #3
0
static PyObject *is_new(PyObject *self, PyObject *args)
{
  return py_boolean_return_value(MSG_IS_NEW(((clawsmail_MessageInfoObject*)self)->msginfo->flags));
}