Ejemplo n.º 1
0
 private void onAddSenderToContacts() {
   if (mMessage != null) {
     try {
       final Address senderEmail = mMessage.getFrom()[0];
       mContacts.createContact(senderEmail);
     } catch (Exception e) {
       Log.e(K9.LOG_TAG, "Couldn't create contact", e);
     }
   }
 }
Ejemplo n.º 2
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();
    }
  }
Ejemplo n.º 3
0
  public void populate(final Message message, final Account account) throws MessagingException {
    final Contacts contacts = K9.showContactName() ? mContacts : null;
    final CharSequence from = Address.toFriendly(message.getFrom(), contacts);
    final CharSequence to =
        Address.toFriendly(message.getRecipients(Message.RecipientType.TO), contacts);
    final CharSequence cc =
        Address.toFriendly(message.getRecipients(Message.RecipientType.CC), contacts);

    Address[] fromAddrs = message.getFrom();
    Address[] toAddrs = message.getRecipients(Message.RecipientType.TO);
    Address[] ccAddrs = message.getRecipients(Message.RecipientType.CC);
    boolean fromMe = mMessageHelper.toMe(account, fromAddrs);

    String counterpartyAddress = null;
    if (fromMe) {
      if (toAddrs.length > 0) {
        counterpartyAddress = toAddrs[0].getAddress();
      } else if (ccAddrs.length > 0) {
        counterpartyAddress = ccAddrs[0].getAddress();
      }
    } else if (fromAddrs.length > 0) {
      counterpartyAddress = fromAddrs[0].getAddress();
    }

    /*
     * Only reset visibility of the subject if populate() was called because a new
     * message is shown. If it is the same, do not force the subject visible, because
     * this breaks the MessageTitleView in the action bar, which may hide our subject
     * if it fits in the action bar but is only called when a new message is shown
     * or the device is rotated.
     */
    if (mMessage == null || mMessage.getId() != message.getId()) {
      mSubjectView.setVisibility(VISIBLE);
    }

    mMessage = message;
    mAccount = account;

    if (K9.showContactPicture()) {
      mContactBadge.setVisibility(View.VISIBLE);
      mContactsPictureLoader = new ContactPictureLoader(mContext, R.drawable.ic_contact_picture);
    } else {
      mContactBadge.setVisibility(View.GONE);
    }

    final String subject = message.getSubject();
    if (StringUtils.isNullOrEmpty(subject)) {
      mSubjectView.setText(mContext.getText(R.string.general_no_subject));
    } else {
      mSubjectView.setText(subject);
    }
    mSubjectView.setTextColor(0xff000000 | defaultSubjectColor);

    String dateTime =
        DateUtils.formatDateTime(
            mContext,
            message.getSentDate().getTime(),
            DateUtils.FORMAT_SHOW_DATE
                | DateUtils.FORMAT_ABBREV_ALL
                | DateUtils.FORMAT_SHOW_TIME
                | DateUtils.FORMAT_SHOW_YEAR);
    mDateView.setText(dateTime);

    if (K9.showContactPicture()) {
      mContactBadge.assignContactFromEmail(counterpartyAddress, true);
      if (counterpartyAddress != null) {
        mContactsPictureLoader.loadContactPicture(counterpartyAddress, mContactBadge);
      } else {
        mContactBadge.setImageResource(R.drawable.ic_contact_picture);
      }
    }

    mFromView.setText(from);

    updateAddressField(mToView, to, mToLabel);
    updateAddressField(mCcView, cc, mCcLabel);
    mAnsweredIcon.setVisibility(message.isSet(Flag.ANSWERED) ? View.VISIBLE : View.GONE);
    mForwardedIcon.setVisibility(message.isSet(Flag.FORWARDED) ? View.VISIBLE : View.GONE);
    mFlagged.setChecked(message.isSet(Flag.FLAGGED));

    int chipColor = mAccount.getChipColor();
    int chipColorAlpha = (!message.isSet(Flag.SEEN)) ? 255 : 127;
    mChip.setBackgroundColor(chipColor);
    mChip.getBackground().setAlpha(chipColorAlpha);

    setVisibility(View.VISIBLE);

    if (mSavedState != null) {
      if (mSavedState.additionalHeadersVisible) {
        showAdditionalHeaders();
      }
      mSavedState = null;
    } else {
      hideAdditionalHeaders();
    }
  }