Exemplo n.º 1
0
Arquivo: news.c Projeto: Mortal/claws
static GSList *news_get_msginfos_for_range(NewsSession *session, FolderItem *item, guint begin, guint end)
{
	GSList *newlist = NULL;
	GSList *llast = NULL;
	MsgInfo *msginfo;
	gint ok;
	clist *msglist = NULL;
	clistiter *cur;
	cm_return_val_if_fail(session != NULL, NULL);
	cm_return_val_if_fail(item != NULL, NULL);

	log_message(LOG_PROTOCOL, _("getting xover %d - %d in %s...\n"),
		    begin, end, item->path);

	news_folder_lock(NEWS_FOLDER(item->folder));
	
	ok = news_select_group(item->folder, item->path, NULL, NULL, NULL);
	if (ok != NEWSNNTP_NO_ERROR) {
		log_warning(LOG_PROTOCOL, _("couldn't set group: %s\n"), item->path);
		news_folder_unlock(NEWS_FOLDER(item->folder));
		return NULL;
	}

	ok = nntp_threaded_xover(item->folder, begin, end, NULL, &msglist);
	
	if (ok != NEWSNNTP_NO_ERROR) {
		log_warning(LOG_PROTOCOL, _("couldn't get xover\n"));
		if (ok == NEWSNNTP_ERROR_STREAM) {
			session_destroy(SESSION(session));
			REMOTE_FOLDER(item->folder)->session = NULL;
		}
		news_folder_unlock(NEWS_FOLDER(item->folder));
		return NULL;
	}

	if (msglist) {
		for (cur = clist_begin(msglist); cur; cur = clist_next(cur)) {
			struct newsnntp_xover_resp_item *ritem = (struct newsnntp_xover_resp_item *)clist_content(cur);
			msginfo = news_parse_xover(ritem);
			
			if (!msginfo) {
				log_warning(LOG_PROTOCOL, _("invalid xover line\n"));
				continue;
			}

			msginfo->folder = item;
			news_set_msg_flags(item, msginfo);
			msginfo->flags.tmp_flags |= MSG_NEWS;

			if (!newlist)
				llast = newlist = g_slist_append(newlist, msginfo);
			else {
				llast = g_slist_append(llast, msginfo);
				llast = llast->next;
			}
		}
		newsnntp_xover_resp_list_free(msglist);
	}

	news_folder_unlock(NEWS_FOLDER(item->folder));

	session_set_access_time(SESSION(session));

	news_get_extra_fields(session, item, newlist);
	
	return newlist;
}
Exemplo n.º 2
0
static clist * read_xover_resp_list(newsnntp * f)
{
  char * line;
  clist * xover_resp_list;
  struct newsnntp_xover_resp_item * n;
  clist * values_list;
  clistiter * current;
  uint32_t article;
  char * subject;
  char * author;
  char * date;
  char * message_id;
  char * references;
  size_t size;
  uint32_t line_count;
  clist * others;
  int r;
  
  xover_resp_list = clist_new();
  if (xover_resp_list == NULL)
    goto err;

  while (1) {
    char * p;
      
    line = read_line(f);

    if (line == NULL)
      goto free_list;

    if (mailstream_is_end_multiline(line))
      break;

    /* parse the data separated with \t */

    values_list = clist_new();
    if (values_list == NULL)
      goto free_list;

    while ((p = strchr(line, '\t')) != NULL) {
      * p = 0;
      p ++;

      r = clist_append(values_list, line);
      if (r < 0)
        goto free_values_list;
      line = p;
    }

    r = clist_append(values_list, line);
    if (r < 0)
      goto free_values_list;

    /* set the known data */
    current = clist_begin(values_list);
    if (current == NULL) {
      clist_free(values_list);
      continue;
    }
    article = 0;
    if (clist_content(current) != NULL) {
      article = atoi((char *) clist_content(current));
    }

    current = clist_next(current);
    if (current == NULL) {
      clist_free(values_list);
      continue;
    }
    subject = clist_content(current);

    current = clist_next(current);
    if (current == NULL) {
      clist_free(values_list);
      continue;
    }
    author = clist_content(current);

    current = clist_next(current);
    if (current == NULL) {
      clist_free(values_list);
      continue;
    }
    date = clist_content(current);

    current = clist_next(current);
    if (current == NULL) {
      clist_free(values_list);
      continue;
    }
    message_id = clist_content(current);

    current = clist_next(current);
    if (current == NULL) {
      clist_free(values_list);
      continue;
    }
    references = clist_content(current);

    current = clist_next(current);
    if (current == NULL) {
      clist_free(values_list);
      continue;
    }
    size = 0;
    if (clist_content(current) != NULL) {
      size = atoi((char *) clist_content(current));
    }

    current = clist_next(current);
    if (current == NULL) {
      clist_free(values_list);
      continue;
    }
    line_count = 0;
    if (clist_content(current) != NULL) {
      line_count = atoi((char *) clist_content(current));
    }

    current = clist_next(current);

    /* make a copy of the other data */
    others = clist_new();
    if (others == NULL) {
      goto free_values_list;
    }

    while (current) {
      char * val;
      char * original_val;

      original_val = clist_content(current);
      val = strdup(original_val);
      if (val == NULL) {
	clist_foreach(others, (clist_func) free, NULL);
	clist_free(others);
	goto free_list;
      }

      r = clist_append(others, val);
      if (r < 0) {
	goto free_list;
      }

      current = clist_next(current);
    }

    clist_free(values_list);

    n = xover_resp_item_new(article, subject, author, date, message_id,
			    references, size, line_count, others);
    if (n == NULL) {
      clist_foreach(others, (clist_func) free, NULL);
      clist_free(others);
      goto free_list;
    }

    r = clist_append(xover_resp_list, n);
    if (r < 0) {
      xover_resp_item_free(n);
      goto free_list;
    }
  }

  return xover_resp_list;

 free_list:
  newsnntp_xover_resp_list_free(xover_resp_list);
 err:
  return NULL;

 free_values_list:
  clist_foreach(values_list, (clist_func) free, NULL);
  clist_free(values_list);
  return NULL;
}
Exemplo n.º 3
0
static int
nntpdriver_get_envelopes_list(mailsession * session,
			      struct mailmessage_list * env_list)
{
  newsnntp * nntp;
  int r;
  struct nntp_session_state_data * data;
  clist * list;
  int done;
  clistiter * cur;
  uint32_t first_seq;
  unsigned int i;

  nntp = get_nntp_session(session);

  data = get_data(session);

  if (data->nntp_group_info == NULL)
    return MAIL_ERROR_BAD_STATE;

  first_seq = data->nntp_group_info->grp_first;

  if (carray_count(env_list->msg_tab) > 0) {
    mailmessage * msg;

    msg = carray_get(env_list->msg_tab, 0);

    first_seq = msg->msg_index;
  }

  if (carray_count(env_list->msg_tab) > 0) {
    i = carray_count(env_list->msg_tab) - 1;
    while (1) {
      mailmessage * msg;
      
      msg = carray_get(env_list->msg_tab, i);
      
      if (msg->msg_fields != NULL) {
        first_seq = msg->msg_index + 1;
        break;
      }
      
      if (i == 0)
        break;
      
      i --;
    }
  }

  if (first_seq > data->nntp_group_info->grp_last) {
    list = NULL;
  }
  else {
    done = FALSE;
    do {
      r = newsnntp_xover_range(nntp, first_seq,
          data->nntp_group_info->grp_last, &list);
      
      switch (r) {
      case NEWSNNTP_ERROR_REQUEST_AUTHORIZATION_USERNAME:
	r = nntpdriver_authenticate_user(session);
	if (r != MAIL_NO_ERROR)
	  return r;
	break;
	
      case NEWSNNTP_WARNING_REQUEST_AUTHORIZATION_PASSWORD:
	r = nntpdriver_authenticate_password(session);
	if (r != MAIL_NO_ERROR)
	  return r;
	break;
	
      case NEWSNNTP_NO_ERROR:
	done = TRUE;
	break;
	
      default:
	return nntpdriver_nntp_error_to_mail_error(r);
      }
    }
    while (!done);
  }

#if 0
  i = 0;
  j = 0;

  if (list != NULL) {
    for(cur = clist_begin(list) ; cur != NULL ; cur = clist_next(cur)) {
      struct newsnntp_xover_resp_item * item;
      struct mailimf_fields * fields;

      item = clist_content(cur);

      while (i < carray_count(env_list->msg_tab)) {
	mailmessage * info;

	info = carray_get(env_list->msg_tab, i);

	if (item->ovr_article == info->msg_index) {

	  if (info->fields == NULL) {
	    r = xover_resp_to_fields(item, &fields);
	    if (r == MAIL_NO_ERROR) {
	      info->fields = fields;
	    }
            
	    info->size = item->ovr_size;

	    carray_set(env_list->msg_tab, j, info);
	    j ++;
	    i ++;
	    break;
	  }
	  else {
	    carray_set(env_list->msg_tab, j, info);
	    j ++;
	  }
	}
	else {
	  if (info->fields != NULL) {
	    carray_set(env_list->msg_tab, j, info);
	    j ++;
	  }
	  else {
            if (info->flags != NULL) {
              info->flags->flags &= ~MAIL_FLAG_NEW;
              info->flags->flags |= MAIL_FLAG_SEEN | MAIL_FLAG_DELETED;
              mailmessage_check(info);
            }
	    mailmessage_free(info);
	    carray_set(env_list->msg_tab, i, NULL);
	  }
	}

	i ++;
      }
    }
  }

  while (i < carray_count(env_list->msg_tab)) {
    mailmessage * info;
    
    info = carray_get(env_list->msg_tab, i);
    if (info->fields != NULL) {
      carray_set(env_list->msg_tab, j, info);
      j ++;
    }
    else {
      if (info->flags != NULL) {
        info->flags->flags &= ~MAIL_FLAG_NEW;
        info->flags->flags |= MAIL_FLAG_SEEN | MAIL_FLAG_DELETED;
        mailmessage_check(info);
      }
      mailmessage_free(info);
      carray_set(env_list->msg_tab, i, NULL);
    }
    
    i ++;
  }

  r = carray_set_size(env_list->msg_tab, j);
  if (r < 0) {
    if (list != NULL)
      newsnntp_xover_resp_list_free(list);
    return MAIL_ERROR_MEMORY;
  }
#endif
  i = 0;

  if (list != NULL) {
    for(cur = clist_begin(list) ; cur != NULL ; cur = clist_next(cur)) {
      struct newsnntp_xover_resp_item * item;
      struct mailimf_fields * fields;

      item = clist_content(cur);

      while (i < carray_count(env_list->msg_tab)) {
	mailmessage * info;

	info = carray_get(env_list->msg_tab, i);

	if (item->ovr_article == info->msg_index) {

	  if (info->msg_fields == NULL) {
            fields = NULL;
	    r = xover_resp_to_fields(item, &fields);
	    if (r == MAIL_NO_ERROR) {
	      info->msg_fields = fields;
	    }
            
	    info->msg_size = item->ovr_size;

	    i ++;
	    break;
	  }
	}
#if 0
	else if ((info->fields == NULL) && (info->flags != NULL)) {
          info->flags->flags &= ~MAIL_FLAG_NEW;
          info->flags->flags |= MAIL_FLAG_CANCELLED;
          mailmessage_check(info);
	}
#endif
        
	i ++;
      }
    }
  }

#if 0
  while (i < env_list->msg_tab->len) {
    mailmessage * info;
    
    info = carray_get(env_list->msg_tab, i);
    if ((info->fields == NULL) && (info->flags != NULL)) {
      info->flags->flags &= ~MAIL_FLAG_NEW;
      info->flags->flags |= MAIL_FLAG_CANCELLED;
      mailmessage_check(info);
    }
    
    i ++;
  }
#endif

  if (list != NULL)
    newsnntp_xover_resp_list_free(list);

  return MAIL_NO_ERROR;
}