Example #1
0
/*
 * Fetch the specified header fields, ie. BODY[HEADER.FIELDS (<fields>)], of
 * the messages.
 */
int
request_fetchfields(const char *server, const char *port, const char *user,
    const char *mesg, const char *headerfields, char **fields, size_t *len)
{
	int t, r, n;
	session *s;
	char *f;

	n = strlen("BODY.PEEK[HEADER.FIELDS ()]") + strlen(headerfields) + 1;
	f = (char *)xmalloc(n * sizeof(char));
	snprintf(f, n, "%s%s%s", "BODY.PEEK[HEADER.FIELDS (", headerfields, ")]");

	if (!(s = session_find(server, port, user)))
		return -1;

	t = imap_fetch(s, mesg, f);
	if ((r = response_fetchbody(s, t, fields, len)) == -1)
		goto fail;

	xfree(f);

	return r;
fail:
	close_connection(s);
	session_destroy(s);

	return -1;
}
Example #2
0
/*
 * Fetch the specified message part, ie. BODY[<part>], of the
 * messages.
 */
int
request_fetchpart(const char *server, const char *port, const char *user,
    const char *mesg, const char *part, char **bodypart, size_t *len)
{
	int t, r, n;
	session *s;
	char *f;

	n = strlen("BODY.PEEK[]") + strlen(part) + 1;
	f = (char *)xmalloc(n * sizeof(char));
	snprintf(f, n, "%s%s%s", "BODY.PEEK[", part, "]");

	if (!(s = session_find(server, port, user)))
		return -1;

	t = imap_fetch(s, mesg, f);
	if ((r = response_fetchbody(s, t, bodypart, len)) == -1)
		goto fail;

	xfree(f);

	return r;
fail:
	close_connection(s);
	session_destroy(s);

	return -1;
}
Example #3
0
static int imap_fetch_section(mailmessage * msg_info,
			      struct mailmime * mime,
			      char ** result, size_t * result_len)
{
  struct mailimap_section * section;
  struct mailimap_fetch_att * fetch_att;
  int r;
  struct mailimap_fetch_type * fetch_type;
  char * text;
  size_t text_length;
  struct mailmime_section * part;

  if (mime->mm_parent == NULL)
    return imap_fetch(msg_info, result, result_len);
  
  r = mailmime_get_section_id(mime, &part);
  if (r != MAILIMF_NO_ERROR)
    return maildriver_imf_error_to_mail_error(r);

  r = imap_section_to_imap_section(part, IMAP_SECTION_MESSAGE, &section);
  mailmime_section_free(part);
  if (r != MAIL_NO_ERROR)
    return r;

  fetch_att = mailimap_fetch_att_new_body_peek_section(section);
  if (fetch_att == NULL) {
    mailimap_section_free(section);
    return MAIL_ERROR_MEMORY;
  }

  fetch_type = mailimap_fetch_type_new_fetch_att(fetch_att);
  if (fetch_type == NULL) {
    mailimap_fetch_att_free(fetch_att);
    return MAIL_ERROR_MEMORY;
  }

  r = fetch_imap(msg_info, fetch_type, &text, &text_length);

  mailimap_fetch_type_free(fetch_type);

  if (r != MAIL_NO_ERROR)
    return r;
  
  * result = text;
  * result_len = text_length;

  return MAIL_NO_ERROR;
}
Example #4
0
/* for SELECT responses */
static CURLcode imap_state_select_resp(struct connectdata *conn,
                                       int imapcode,
                                       imapstate instate)
{
  CURLcode result = CURLE_OK;
  struct SessionHandle *data = conn->data;
  (void)instate; /* no use for this yet */

  if(imapcode != 'O') {
    failf(data, "Select failed");
    result = CURLE_LOGIN_DENIED;
  }
  else
    result = imap_fetch(conn);
  return result;
}
Example #5
0
/*
 * Fetch the text, ie. BODY[TEXT], of the messages.
 */
int
request_fetchtext(const char *server, const char *port, const char *user,
    const char *mesg, char **text, size_t *len)
{
	int t, r;
	session *s;

	if (!(s = session_find(server, port, user)))
		return -1;

	t = imap_fetch(s, mesg, "BODY.PEEK[TEXT]");
	if ((r = response_fetchbody(s, t, text, len)) == -1)
		goto fail;

	return r;
fail:
	close_connection(s);
	session_destroy(s);

	return -1;
}
Example #6
0
/*
 * Fetch the body structure, ie. BODYSTRUCTURE, of the messages.
 */
int
request_fetchstructure(const char *server, const char *port, const char *user,
    const char *mesg, char **structure)
{
	int t, r;
	session *s;

	if (!(s = session_find(server, port, user)))
		return -1;

	t = imap_fetch(s, mesg, "BODYSTRUCTURE");
	if ((r = response_fetchstructure(s, t, structure)) == -1)
		goto fail;

	return r;
fail:
	close_connection(s);
	session_destroy(s);

	return -1;
}
Example #7
0
/*
 * Fetch the INTERNALDATE of the messages.
 */
int
request_fetchdate(const char *server, const char *port, const char *user,
    const char *mesg, char **date)
{
	int t, r;
	session *s;

	if (!(s = session_find(server, port, user)))
		return -1;

	t = imap_fetch(s, mesg, "INTERNALDATE");
	if ((r = response_fetchdate(s, t, date)) == -1)
		goto fail;

	return r;
fail:
	close_connection(s);
	session_destroy(s);

	return -1;
}
Example #8
0
/*
 * Fetch the FLAGS of the messages.
 */
int
request_fetchflags(const char *server, const char *port, const char *user,
    const char *mesg, char **flags)
{
	int t, r;
	session *s;

	if (!(s = session_find(server, port, user)))
		return -1;

	t = imap_fetch(s, mesg, "FLAGS");
	if ((r = response_fetchflags(s, t, flags)) == -1)
		goto fail;

	return r;
fail:
	close_connection(s);
	session_destroy(s);

	return -1;
}