public void sendUdpOneWay(Message message, EndPoint to) {
    EndPoint from = message.getFrom();
    if (message.getFrom().equals(to)) {
      MessagingService.receive(message);
      return;
    }

    UdpConnection connection = null;
    try {
      connection = new UdpConnection();
      connection.init();
      connection.write(message, to);
    } catch (IOException e) {
      logger_.warn(LogUtil.throwableToString(e));
    } finally {
      if (connection != null) connection.close();
    }
  }
  /*
      Use this version for fire and forget style messaging.
  */
  public void sendOneWay(Message message, EndPoint to) {
    // do local deliveries
    if (message.getFrom().equals(to)) {
      MessagingService.receive(message);
      return;
    }

    Runnable tcpWriteEvent = new MessageSerializationTask(message, to);
    messageSerializerExecutor_.execute(tcpWriteEvent);
  }
Esempio n. 3
0
  private void sendMessageTo(ArrayList<String> addresses, Message message)
      throws MessagingException {
    boolean possibleSend = false;

    close();
    open();

    message.setEncoding(m8bitEncodingAllowed ? "8bit" : null);
    // If the message has attachments and our server has told us about a limit on
    // the size of messages, count the message's size before sending it
    if (mLargestAcceptableMessage > 0 && ((LocalMessage) message).hasAttachments()) {
      if (message.calculateSize() > mLargestAcceptableMessage) {
        MessagingException me = new MessagingException("Message too large for server");
        me.setPermanentFailure(possibleSend);
        throw me;
      }
    }

    Address[] from = message.getFrom();
    try {
      // TODO: Add BODY=8BITMIME parameter if appropriate?
      executeSimpleCommand("MAIL FROM:" + "<" + from[0].getAddress() + ">");
      for (String address : addresses) {
        executeSimpleCommand("RCPT TO:" + "<" + address + ">");
      }
      executeSimpleCommand("DATA");

      EOLConvertingOutputStream msgOut =
          new EOLConvertingOutputStream(
              new SmtpDataStuffing(
                  new LineWrapOutputStream(new BufferedOutputStream(mOut, 1024), 1000)));

      message.writeTo(msgOut);

      // We use BufferedOutputStream. So make sure to call flush() !
      msgOut.flush();

      possibleSend = true; // After the "\r\n." is attempted, we may have sent the message
      executeSimpleCommand("\r\n.");
    } catch (Exception e) {
      MessagingException me = new MessagingException("Unable to send message", e);

      // "5xx text" -responses are permanent failures
      String msg = e.getMessage();
      if (msg != null && msg.startsWith("5")) {
        Log.w(K9.LOG_TAG, "handling 5xx SMTP error code as a permanent failure");
        possibleSend = false;
      }

      me.setPermanentFailure(possibleSend);
      throw me;
    } finally {
      close();
    }
  }