Esempio n. 1
0
/*
 * Append supplied message to the specified mailbox.
 */
int
request_append(session *ssn, const char *mbox, const char *mesg, size_t
    mesglen, const char *flags, const char *date)
{
	int t, r;
	const char *m;

	m = apply_namespace(mbox, ssn->ns.prefix, ssn->ns.delim);

	TRY(t = send_request(ssn, "APPEND \"%s\"%s%s%s%s%s%s {%d}", m,
	    (flags ? " (" : ""), (flags ? flags : ""),
	    (flags ? ")" : ""), (date ? " \"" : ""),
	    (date ? date : ""), (date ? "\"" : ""), mesglen));
	TRY(r = response_continuation(ssn, t));
	if (r == STATUS_CONTINUE) {
		TRY(send_continuation(ssn, mesg, mesglen)); 
		TRY(r = response_generic(ssn, t));
	}

	if (r == STATUS_TRYCREATE) {
		TRY(t = send_request(ssn, "CREATE \"%s\"", m));
		TRY(response_generic(ssn, t));
		if (get_option_boolean("subscribe")) {
			TRY(t = send_request(ssn, "SUBSCRIBE \"%s\"", m));
			TRY(response_generic(ssn, t));
		}
		TRY(t = send_request(ssn, "APPEND \"%s\"%s%s%s%s%s%s {%d}", m,
		    (flags ? " (" : ""), (flags ? flags : ""),
		    (flags ? ")" : ""), (date ? " \"" : ""),
		    (date ? date : ""), (date ? "\"" : ""), mesglen));
		TRY(r = response_continuation(ssn, t));
		if (r == STATUS_CONTINUE) {
			TRY(send_continuation(ssn, mesg, mesglen)); 
			TRY(r = response_generic(ssn, t));
		}
	}

	return r;
}
Esempio n. 2
0
/*
 * Process the data that server sent due to IMAP AUTHENTICATE client request.
 */
int
response_authenticate(session *ssn, int tag, unsigned char **cont)
{
	int r;
	regexp *re;

	re = &responses[RESPONSE_AUTHENTICATE];

	if ((r = response_continuation(ssn, tag)) == STATUS_CONTINUE &&
	    !regexec(re->preg, ibuf.data, re->nmatch, re->pmatch, 0))
		*cont = (unsigned char *)xstrndup(ibuf.data +
		    re->pmatch[1].rm_so, re->pmatch[1].rm_eo -
		    re->pmatch[1].rm_so);

	return r;
}
Esempio n. 3
0
/*
 * Append supplied message to the specified mailbox.
 */
int
request_append(const char *server, const char *port, const char *user,
    const char *mbox, const char *mesg, size_t mesglen, const char *flags,
    const char *date)
{
	int t, r;
	session *s;
	const char *m;

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

	m = apply_namespace(mbox, s->ns.prefix, s->ns.delim);

	do {
		if ((t = imap_append(s, m, flags, date, mesglen)) == -1)
			goto fail;
		if ((r = response_continuation(s)) == -1)
			goto fail;

		switch (r) {
		case STATUS_RESPONSE_CONTINUE:
			if (imap_continuation(s, mesg, mesglen) == -1)
				goto fail;
			if ((r = response_generic(s, t)) == -1)
				goto fail;
			break;
		case STATUS_RESPONSE_TRYCREATE:
			if (create_mailbox(s, mbox) == -1)
				goto fail;
			break;
		case -1:
			goto fail;
			break;
		}
	} while (r == STATUS_RESPONSE_TRYCREATE);

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

	return -1;
}
Esempio n. 4
0
int
request_idle(const char *server, const char *port, const char *user)
{
	int t, rg, ri;
	session *s;

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


	if (!(s->capabilities & CAPABILITY_IDLE))
		return -1;

	do {
		ri = 0;

		t = imap_idle(s);

		if ((rg = response_continuation(s)) == -1)
			goto fail;

		if (rg == STATUS_RESPONSE_CONTINUE) {
			if ((ri = response_idle(s, t)) == -1)
				goto fail;

			imap_done(s);

			if ((rg = response_generic(s, t)) == -1)
				goto fail;
		}
	} while (ri == STATUS_RESPONSE_TIMEOUT);

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

	return -1;
}
Esempio n. 5
0
int
request_idle(session *ssn, char **event)
{
	int t, r, ri;

	if (!(ssn->capabilities & CAPABILITY_IDLE))
		return STATUS_BAD;

	do {
		ri = 0;

		TRY(t = send_request(ssn, "IDLE"));
		TRY(r = response_continuation(ssn, t));
		if (r == STATUS_CONTINUE) {
			TRY(ri = response_idle(ssn, t, event));
			TRY(send_continuation(ssn, "DONE", strlen("DONE")));
			TRY(r = response_generic(ssn, t));
		}
	} while (ri == STATUS_TIMEOUT);

	return r;
}