Example #1
0
/***********************************************************************
 *
 * smtp_perform()
 *
 * This is the actual DO function for SMTP. Get a file/directory according to
 * the options previously setup.
 */
static CURLcode smtp_perform(struct connectdata *conn, bool *connected,
                             bool *dophase_done)
{
  /* This is SMTP and no proxy */
  CURLcode result = CURLE_OK;

  DEBUGF(infof(conn->data, "DO phase starts\n"));

  if(conn->data->set.opt_no_body) {
    /* Requested no body means no transfer */
    struct FTP *smtp = conn->data->state.proto.smtp;
    smtp->transfer = FTPTRANSFER_INFO;
  }

  *dophase_done = FALSE; /* not done yet */

  /* Start the first command in the DO phase */
  result = smtp_mail(conn);
  if(result)
    return result;

  /* Run the state-machine */
  if(conn->data->state.used_interface == Curl_if_multi)
    result = smtp_multi_statemach(conn, dophase_done);
  else {
    result = smtp_easy_statemach(conn);
    *dophase_done = TRUE; /* with the easy interface we are done here */
  }
  *connected = conn->bits.tcpconnect[FIRSTSOCKET];

  if(*dophase_done)
    DEBUGF(infof(conn->data, "DO phase is complete\n"));

  return result;
}
Example #2
0
static int mail_one(const char *spool)
{
  FILE *fp, *pipo;
  char buff[MAX_LINE_SIZE];
  char *to=NULL;
  char *subj=NULL;
  int rc;

  fp = fopen(spool, "r");
  if (!fp) {
    Logit("Mail_one(%s) : failed to open: %d(%s)"
    , spool, errno, strerror(errno));
    return -1;
  }

  while(fgets(buff, sizeof buff, fp)) {
    switch(buff[0]) {
    case 't': to = mystrdup(buff+2); break;
    case 's': subj = mystrdup(buff+2); break;
    case '\0': case '\n': case ' ': goto body;
    default: continue;
  }}
body:

  if (!to) {
    Logit("Mail_one(%s) : no \"to:\"", spool);
    fclose(fp);
    if (subj) free(subj);
    return -2;}

  to[strlen(to)-1] = 0;
  if (subj) subj[strlen(subj)-1] = 0;

  if (memcmp(conffile.mail_program, "SMTP", 4)) {
    if (subj) sprintf(buff, "%s -s \"%s\" %s", conffile.mail_program, subj, to);
    else sprintf(buff, "%s %s", conffile.mail_program, to);
    if (conffile.debug_mailer) Logit("Mail_one(%s) : opening pipe: \"%s\""
       , spool, buff);
    pipo = popen(buff, "w");
    fprintf(pipo, "From: %s\n", conffile.server_email);
    if (conffile.smtp_reply_to) fprintf(pipo, "Reply-To: %s\n", conffile.smtp_reply_to);
    fprintf(pipo, "X-NNGS-SMTP: %s\n", "No, Sir!" );
    fprintf(pipo, "\n");
    while(fgets(buff, sizeof buff, fp)) fputs(buff, pipo);
    fclose(pipo);
    rc = 0;
  } else {
    rc =  smtp_mail(fp, to, subj);
    if (conffile.debug_mailer) Logit("Smtp_mail(to=%s,Subj=%s) returned %d"
       , to, subj, rc);
  }

  if (rc >= 0) unlink(spool);
  fclose(fp);
  if (to) free(to);
  if (subj) free(subj);
  return (rc>=0) ? 0: -1;
}
Example #3
0
bool smtp_client::mail_from(const char* from)
{
	if (from == NULL || *from == 0)
	{
		logger_error("from null");
		return false;
	}
	return smtp_mail(client_, from) == 0 ? true : false;
}
static gboolean
smtp_transport_send_to_sync (CamelTransport *transport,
                             CamelMimeMessage *message,
                             CamelAddress *from,
                             CamelAddress *recipients,
			     gboolean *out_sent_message_saved,
                             GCancellable *cancellable,
                             GError **error)
{
	CamelSmtpTransport *smtp_transport = CAMEL_SMTP_TRANSPORT (transport);
	CamelInternetAddress *cia;
	gboolean has_8bit_parts;
	const gchar *addr;
	gint i, len;

	smtp_debug_print_server_name (CAMEL_SERVICE (transport), "Sending with");

	if (!smtp_transport->connected) {
		g_set_error (
			error, CAMEL_SERVICE_ERROR,
			CAMEL_SERVICE_ERROR_NOT_CONNECTED,
			_("Cannot send message: service not connected."));
		return FALSE;
	}

	if (!camel_internet_address_get (CAMEL_INTERNET_ADDRESS (from), 0, NULL, &addr)) {
		g_set_error (
			error, CAMEL_ERROR, CAMEL_ERROR_GENERIC,
			_("Cannot send message: sender address not valid."));
		return FALSE;
	}

	camel_operation_push_message (cancellable, _("Sending message"));

	/* find out if the message has 8bit mime parts */
	has_8bit_parts = camel_mime_message_has_8bit_parts (message);

	/* If the connection needs a ReSET, then do so */
	if (smtp_transport->need_rset &&
	    !smtp_rset (smtp_transport, cancellable, error)) {
		camel_operation_pop_message (cancellable);
		return FALSE;
	}
	smtp_transport->need_rset = FALSE;

	/* rfc1652 (8BITMIME) requires that you notify the ESMTP daemon that
	 * you'll be sending an 8bit mime message at "MAIL FROM:" time. */
	if (!smtp_mail (
		smtp_transport, addr, has_8bit_parts, cancellable, error)) {
		camel_operation_pop_message (cancellable);
		return FALSE;
	}

	len = camel_address_length (recipients);
	if (len == 0) {
		g_set_error (
			error, CAMEL_ERROR, CAMEL_ERROR_GENERIC,
			_("Cannot send message: no recipients defined."));
		camel_operation_pop_message (cancellable);
		smtp_transport->need_rset = TRUE;
		return FALSE;
	}

	cia = CAMEL_INTERNET_ADDRESS (recipients);
	for (i = 0; i < len; i++) {
		gchar *enc;

		if (!camel_internet_address_get (cia, i, NULL, &addr)) {
			g_set_error (
				error, CAMEL_ERROR, CAMEL_ERROR_GENERIC,
				_("Cannot send message: "
				"one or more invalid recipients"));
			camel_operation_pop_message (cancellable);
			smtp_transport->need_rset = TRUE;
			return FALSE;
		}

		enc = camel_internet_address_encode_address (NULL, NULL, addr);
		if (!smtp_rcpt (smtp_transport, enc, cancellable, error)) {
			g_free (enc);
			camel_operation_pop_message (cancellable);
			smtp_transport->need_rset = TRUE;
			return FALSE;
		}
		g_free (enc);
	}

	if (!smtp_data (smtp_transport, message, cancellable, error)) {
		camel_operation_pop_message (cancellable);
		smtp_transport->need_rset = TRUE;
		return FALSE;
	}

	camel_operation_pop_message (cancellable);

	return TRUE;
}