Search in sources :

Example 11 with Email

use of i2p.bote.email.Email in project i2p.i2p-bote by i2p.

the class JSPHelper method getNewEmailNotificationContent.

public String getNewEmailNotificationContent() {
    String title = "I2P-Bote";
    String body = "";
    try {
        Email email = I2PBote.getInstance().getInbox().getLatestUnreadEmail();
        if (email != null) {
            title = "I2P-Bote: " + getNameAndShortDestination(email.getOneFromAddress());
            body = email.getSubject();
        }
    } catch (PasswordException e) {
    } catch (MessagingException e) {
    } catch (IOException e) {
    } catch (GeneralSecurityException e) {
    }
    if (body == "")
        body = _t("New email received");
    return "<script>\nnotifTitle=\"" + title + "\";\nnotifBody=\"" + body + "\";\n</script>";
}
Also used : PasswordException(i2p.bote.fileencryption.PasswordException) Email(i2p.bote.email.Email) MessagingException(javax.mail.MessagingException) GeneralSecurityException(java.security.GeneralSecurityException) IOException(java.io.IOException)

Example 12 with Email

use of i2p.bote.email.Email in project i2p.i2p-bote by i2p.

the class SendEmailTag method doEndTag.

@Override
public int doEndTag() throws JspException {
    JspWriter out = pageContext.getOut();
    Email email = new Email(includeSentTime);
    String statusMessage;
    if (recipients.isEmpty())
        statusMessage = _t("Error: Please add at least one recipient.");
    else
        try {
            // set addresses
            InternetAddress ia = new InternetAddress(senderAddress);
            email.setFrom(ia);
            // We must continue to set "Sender:" even with only one mailbox
            // in "From:", which is against RFC 2822 but required for older
            // Bote versions to see a sender (and validate the signature).
            email.setSender(ia);
            email.setSubject(subject, "UTF-8");
            for (Recipient recipient : recipients) email.addRecipient(recipient.type, recipient.address);
            // TODO: Comment out until we determine if this is necessary
            // email.fixAddresses();
            // set the text and add attachments
            email.setContent(message, attachments);
            // send the email
            I2PBote.getInstance().sendEmail(email);
            // delete attachment temp files
            for (Attachment attachment : attachments) {
                if (!attachment.clean())
                    log.error("Can't clean up attachment: <" + attachment + ">");
            }
            statusMessage = _t("The email has been queued for sending.");
        } catch (PasswordException e) {
            throw new JspException(e);
        } catch (NoIdentityForSenderException e) {
            statusMessage = _t("Error sending email: {0}", _t("No identity matches the sender/from field: {0}", e.getSender()));
            log.error("Error sending email", e);
        } catch (AddressException e) {
            statusMessage = _t("Error sending email: {0}", _t("Address doesn't contain an Email Destination or an external address: {0}", e.getRef()));
            log.error("Error sending email", e);
        } catch (Exception e) {
            statusMessage = _t("Error sending email: {0}", e.getLocalizedMessage());
            log.error("Error sending email", e);
        }
    try {
        out.println(statusMessage);
    } catch (IOException e) {
        log.error("Can't write output to HTML page", e);
    }
    return EVAL_PAGE;
}
Also used : PasswordException(i2p.bote.fileencryption.PasswordException) JspException(javax.servlet.jsp.JspException) InternetAddress(javax.mail.internet.InternetAddress) Email(i2p.bote.email.Email) NoIdentityForSenderException(i2p.bote.email.NoIdentityForSenderException) AddressException(javax.mail.internet.AddressException) Attachment(i2p.bote.email.Attachment) FileAttachment(i2p.bote.email.FileAttachment) IOException(java.io.IOException) JspWriter(javax.servlet.jsp.JspWriter) AddressException(javax.mail.internet.AddressException) PasswordException(i2p.bote.fileencryption.PasswordException) JspException(javax.servlet.jsp.JspException) IOException(java.io.IOException) NoIdentityForSenderException(i2p.bote.email.NoIdentityForSenderException)

Example 13 with Email

use of i2p.bote.email.Email in project i2p.i2p-bote by i2p.

the class EmailListAdapter method onBindViewHolder.

// Replace the contents of a view (invoked by the layout manager)
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
    switch(holder.getItemViewType()) {
        case R.layout.listitem_empty:
            ((TextView) holder.itemView).setText(mCtx.getResources().getString(R.string.folder_empty));
            break;
        case R.layout.listitem_incomplete:
            ((TextView) holder.itemView).setText(mCtx.getResources().getQuantityString(R.plurals.incomplete_emails, mIncompleteEmails, mIncompleteEmails));
            break;
        case R.layout.listitem_email:
            final EmailViewHolder evh = (EmailViewHolder) holder;
            final Email email = getEmail(position);
            evh.picture.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View view) {
                    selectEmail(evh.getAdapterPosition(), evh.getItemId(), true);
                }
            });
            evh.itemView.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View view) {
                    selectEmail(evh.getAdapterPosition(), evh.getItemId(), false);
                }
            });
            evh.itemView.setOnLongClickListener(new View.OnLongClickListener() {

                @Override
                public boolean onLongClick(View view) {
                    selectEmail(evh.getAdapterPosition(), evh.getItemId(), true);
                    return true;
                }
            });
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB)
                evh.itemView.setSelected(isSelected(position));
            else
                evh.itemView.setActivated(isSelected(position));
            try {
                boolean isSentEmail = BoteHelper.isSentEmail(email);
                String otherAddress;
                if (isSentEmail)
                    otherAddress = email.getOneRecipient();
                else
                    otherAddress = email.getOneFromAddress();
                Bitmap pic = BoteHelper.getPictureForAddress(otherAddress);
                if (pic != null)
                    evh.picture.setImageBitmap(pic);
                else if (isSentEmail || !email.isAnonymous()) {
                    ViewGroup.LayoutParams lp = evh.picture.getLayoutParams();
                    evh.picture.setImageBitmap(BoteHelper.getIdenticonForAddress(otherAddress, lp.width, lp.height));
                } else
                    evh.picture.setImageDrawable(mCtx.getResources().getDrawable(R.drawable.ic_contact_picture));
                evh.subject.setText(email.getSubject());
                evh.address.setText(BoteHelper.getNameAndShortDestination(otherAddress));
                Date date = email.getSentDate();
                if (date == null)
                    date = email.getReceivedDate();
                if (date != null) {
                    DateFormat df;
                    if (date.before(BOUNDARY_DAY.getTime())) {
                        if (// Sent before this year
                        date.before(BOUNDARY_YEAR.getTime()))
                            df = DATE_BEFORE_THIS_YEAR;
                        else
                            // Sent this year before today
                            df = DATE_THIS_YEAR;
                    } else
                        // Sent today
                        df = DATE_TODAY;
                    evh.sent.setText(df.format(date));
                    evh.sent.setVisibility(View.VISIBLE);
                } else
                    evh.sent.setVisibility(View.GONE);
                evh.emailAttachment.setVisibility(View.GONE);
                for (Part part : email.getParts()) {
                    if (Part.ATTACHMENT.equalsIgnoreCase(part.getDisposition())) {
                        evh.emailAttachment.setVisibility(View.VISIBLE);
                        break;
                    }
                }
                evh.subject.setTypeface(email.isUnread() ? Typeface.DEFAULT_BOLD : Typeface.DEFAULT);
                evh.address.setTypeface(email.isUnread() ? Typeface.DEFAULT_BOLD : Typeface.DEFAULT);
                if (email.isAnonymous() && !isSentEmail) {
                    if (email.isUnread())
                        evh.address.setTypeface(Typeface.DEFAULT, Typeface.BOLD_ITALIC);
                    else
                        evh.address.setTypeface(Typeface.DEFAULT, Typeface.ITALIC);
                }
                // or set email delivery status if we sent it.
                if (mIsOutbox) {
                    evh.emailStatus.setText(BoteHelper.getEmailStatusText(mCtx, email, false));
                    evh.emailStatus.setVisibility(View.VISIBLE);
                } else if (isSentEmail) {
                    if (email.isDelivered()) {
                        evh.emailStatus.setVisibility(View.GONE);
                    } else {
                        evh.emailStatus.setText(email.getDeliveryPercentage() + "%");
                        evh.emailStatus.setVisibility(View.VISIBLE);
                    }
                }
                evh.emailDelivered.setVisibility(!mIsOutbox && isSentEmail && email.isDelivered() ? View.VISIBLE : View.GONE);
            } catch (Exception e) {
                evh.subject.setText("ERROR: " + e.getMessage());
            }
            evh.content.setText(email.getText());
            break;
        default:
            break;
    }
}
Also used : Email(i2p.bote.email.Email) ImageView(android.widget.ImageView) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) View(android.view.View) Date(java.util.Date) Bitmap(android.graphics.Bitmap) Part(javax.mail.Part) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) TextView(android.widget.TextView)

Example 14 with Email

use of i2p.bote.email.Email in project i2p.i2p-bote by i2p.

the class AttachmentProviderTests method createEmailWithAttachment.

private Uri createEmailWithAttachment(Attachment attachment) throws Exception {
    List<Attachment> attachments = new ArrayList<Attachment>();
    attachments.add(attachment);
    Email email = new Email(false);
    email.setContent("", attachments);
    I2PBote.getInstance().getInbox().add(email);
    return AttachmentProvider.getUriForAttachment(I2PBote.getInstance().getInbox().getName(), email.getMessageID(), 1);
}
Also used : Email(i2p.bote.email.Email) ArrayList(java.util.ArrayList) Attachment(i2p.bote.email.Attachment) ContentAttachment(i2p.bote.android.util.ContentAttachment)

Example 15 with Email

use of i2p.bote.email.Email in project i2p.i2p-bote by i2p.

the class AttachmentProviderTests method tearDown.

@After
public void tearDown() throws Exception {
    super.tearDown();
    EmailFolder inbox = I2PBote.getInstance().getInbox();
    for (Email email : BoteHelper.getEmails(inbox, null, true)) {
        inbox.delete(email.getMessageID());
    }
    System.setProperty("i2pbote.initialized", "false");
}
Also used : Email(i2p.bote.email.Email) EmailFolder(i2p.bote.folder.EmailFolder) After(org.junit.After)

Aggregations

Email (i2p.bote.email.Email)24 PasswordException (i2p.bote.fileencryption.PasswordException)10 MessagingException (javax.mail.MessagingException)8 IOException (java.io.IOException)7 GeneralSecurityException (java.security.GeneralSecurityException)6 InternetAddress (javax.mail.internet.InternetAddress)6 View (android.view.View)4 ImageView (android.widget.ImageView)4 TextView (android.widget.TextView)4 Address (javax.mail.Address)4 Bitmap (android.graphics.Bitmap)3 Attachment (i2p.bote.email.Attachment)3 EmailIdentity (i2p.bote.email.EmailIdentity)3 Test (org.junit.Test)3 SuppressLint (android.annotation.SuppressLint)2 ContentAttachment (i2p.bote.android.util.ContentAttachment)2 Person (i2p.bote.android.util.Person)2 ContactsCompletionView (i2p.bote.android.widget.ContactsCompletionView)2 NoIdentityForSenderException (i2p.bote.email.NoIdentityForSenderException)2 EmailFolder (i2p.bote.folder.EmailFolder)2