Esempio n. 1
0
void procmsg_update_unread_children(MsgInfo *info, gboolean newly_marked)
{
	GSList *children = procmsg_find_children(info);
	GSList *cur;
	for (cur = children; cur != NULL; cur = g_slist_next(cur)) {
		MsgInfo *tmp = (MsgInfo *)cur->data;
		if(MSG_IS_UNREAD(tmp->flags) && !MSG_IS_IGNORE_THREAD(tmp->flags)) {
			if(newly_marked) 
				info->folder->unreadmarked_msgs++;
			else
				info->folder->unreadmarked_msgs--;
			folder_item_update(info->folder, F_ITEM_UPDATE_MSGCNT);
		}
		procmsg_msginfo_free(tmp);
	}
	g_slist_free(children);
}
Esempio n. 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();
}
Esempio n. 3
0
static PyObject *is_unread(PyObject *self, PyObject *args)
{
  return py_boolean_return_value(MSG_IS_UNREAD(((clawsmail_MessageInfoObject*)self)->msginfo->flags));
}
Esempio n. 4
0
void exec_autoforward_cb(GObject *obj, FolderItem *item, const gchar *file, guint num)
{
  PrefsCommon *prefs_common;
  PrefsAccount *ac;

  gchar *rcpath;
  GSList* to_list=NULL;

  gchar *to;
  GError *errval;
  gboolean forward_all;

  gsize gz=0;
  gchar **folders;
  gboolean bmatch;
  int nindex;
  
  if (g_enable!=TRUE){
    return;
  }
  if (item->stype != F_NORMAL && item->stype != F_INBOX){
    return;
  }

  prefs_common = prefs_common_get();
  if (prefs_common->online_mode != TRUE){
    return;
  }

  ac = (PrefsAccount*)account_get_default();
  g_return_if_fail(ac != NULL);

  /* check item->path for filter */
  g_print("[DEBUG] %s:%s name:%s\n", G_STRLOC, G_STRFUNC, item->name);
  g_print("[DEBUG] %s:%s path:%s\n", G_STRLOC, G_STRFUNC,  item->path);

#if 0
  MsgInfo *msginfo = folder_item_get_msginfo(item, num);
  debug_print("[DEBUG] flags:%08x UNREAD:%08x NEW:%08x MARKED:%08x ", msginfo->flags, MSG_UNREAD, MSG_NEW, MSG_MARKED);
  debug_print("[DEBUG] perm_flags:%08x \n", msginfo->flags.perm_flags);
  debug_print("[DEBUG] tmp_flags:%08x \n", msginfo->flags.tmp_flags);
  if ( g_unreadonly_flg != FALSE){
    debug_print("[DEBUG] unreadonly flag:%s\n", g_unreadonly_flg ? "true" : "false");
    if (MSG_IS_UNREAD(msginfo->flags)){
      debug_print("[DEBUG] MSG_IS_UNREAD:true");
    } else {
      return;
    }
  }
#endif    

  rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, "autoforwardrc", NULL);

  g_keyfile = g_key_file_new();
  g_key_file_load_from_file(g_keyfile, rcpath, G_KEY_FILE_KEEP_COMMENTS, NULL);
  
  to=g_key_file_get_string (g_keyfile, "forward", "to", NULL);
  debug_print("[DEBUG] to:%s", to);
  to_list = address_list_append(to_list, to);


  forward_all = g_key_file_get_boolean (g_keyfile, "forward", "all", &errval);
  if (forward_all != TRUE){
    if (errval) {
      switch (errval->code){
      case G_KEY_FILE_ERROR_INVALID_VALUE:
      case G_KEY_FILE_ERROR_KEY_NOT_FOUND:
        forward_all=TRUE;
        break;
      default:
        break;
      }
    }
  }

  bmatch = FALSE;
  if (forward_all != TRUE){
    folders = g_key_file_get_string_list(g_keyfile, "forward", "folder", &gz, NULL);
    if (gz != 0) {
      /* match or not */
      nindex = 0;
      for (nindex = 0; nindex < gz; nindex++){
        if (g_strcmp0(folders[nindex], item->path) == 0){
          bmatch = TRUE;
          debug_print("[DEBUG] %s %s => match\n", folders[nindex], item->path);
        }
      }
    } else {
      bmatch = FALSE;
    }
  }else{
    bmatch = TRUE;
  }
  g_free(rcpath);
  g_return_if_fail(to_list != NULL);

  g_print("[DEBUG] item->path:%s\n", item->path);
  g_print("[DEBUG] bmatch:%d\n", bmatch);
    
  g_return_if_fail(bmatch == TRUE);

  syl_plugin_send_message_set_forward_flags(ac->address);
  syl_plugin_send_message(file, ac, to_list);
}