Search in sources :

Example 6 with PasswordException

use of i2p.bote.fileencryption.PasswordException in project i2p.i2p-bote by i2p.

the class EditIdentityFragment method initializeIdentity.

private void initializeIdentity() {
    if (mKey == null) {
        // Show the encryption choice field
        CryptoAdapter adapter = new CryptoAdapter(getActivity());
        mCryptoField.setAdapter(adapter);
        mCryptoField.setSelection(mDefaultPos);
        mCryptoField.setVisibility(View.VISIBLE);
        // If no identities, set this as default by default
        try {
            mDefaultField.setChecked(I2PBote.getInstance().getIdentities().size() == 0);
        } catch (PasswordException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (GeneralSecurityException e) {
            e.printStackTrace();
        }
    } else {
        // Load the identity to edit
        try {
            EmailIdentity identity = BoteHelper.getIdentity(mKey);
            String pic = identity.getPictureBase64();
            if (pic != null && !pic.isEmpty()) {
                setPictureB64(pic);
            }
            mNameField.setText(identity.getPublicName());
            mDescField.setText(identity.getDescription());
            mDefaultField.setChecked(identity.isDefaultIdentity());
        } catch (PasswordException e) {
            // TODO Handle
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Handle
            e.printStackTrace();
        } catch (GeneralSecurityException e) {
            // TODO Handle
            e.printStackTrace();
        }
    }
}
Also used : PasswordException(i2p.bote.fileencryption.PasswordException) EmailIdentity(i2p.bote.email.EmailIdentity) GeneralSecurityException(java.security.GeneralSecurityException) IOException(java.io.IOException)

Example 7 with PasswordException

use of i2p.bote.fileencryption.PasswordException in project i2p.i2p-bote by i2p.

the class BoteService method emailReceived.

// NewEmailListener
@Override
public void emailReceived(String messageId) {
    NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    NotificationCompat.Builder b = new NotificationCompat.Builder(this).setAutoCancel(true).setSmallIcon(R.drawable.ic_notif).setDefaults(Notification.DEFAULT_ALL);
    try {
        EmailFolder inbox = I2PBote.getInstance().getInbox();
        // Set the new email as \Recent
        inbox.setRecent(messageId, true);
        // Now display/update notification with all \Recent emails
        List<Email> newEmails = BoteHelper.getRecentEmails(inbox);
        int numNew = newEmails.size();
        switch(numNew) {
            case 0:
                nm.cancel(NOTIF_ID_NEW_EMAIL);
                return;
            case 1:
                Email email = newEmails.get(0);
                String fromAddress = email.getOneFromAddress();
                Bitmap picture = BoteHelper.getPictureForAddress(fromAddress);
                if (picture != null)
                    b.setLargeIcon(picture);
                else if (!email.isAnonymous()) {
                    int width = getResources().getDimensionPixelSize(R.dimen.notification_large_icon_width);
                    int height = getResources().getDimensionPixelSize(R.dimen.notification_large_icon_height);
                    b.setLargeIcon(BoteHelper.getIdenticonForAddress(fromAddress, width, height));
                } else
                    b.setSmallIcon(R.drawable.ic_contact_picture);
                b.setContentTitle(BoteHelper.getNameAndShortDestination(fromAddress));
                b.setContentText(email.getSubject());
                Intent vei = new Intent(this, ViewEmailActivity.class);
                vei.putExtra(ViewEmailActivity.FOLDER_NAME, inbox.getName());
                vei.putExtra(ViewEmailActivity.MESSAGE_ID, email.getMessageID());
                vei.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                PendingIntent pvei = PendingIntent.getActivity(this, 0, vei, PendingIntent.FLAG_UPDATE_CURRENT);
                b.setContentIntent(pvei);
                break;
            default:
                b.setContentTitle(getResources().getQuantityString(R.plurals.n_new_emails, numNew, numNew));
                HashSet<Address> recipients = new HashSet<Address>();
                String bigText = "";
                for (Email ne : newEmails) {
                    recipients.add(BoteHelper.getOneLocalRecipient(ne));
                    bigText += BoteHelper.getNameAndShortDestination(ne.getOneFromAddress());
                    bigText += ": " + ne.getSubject() + "\n";
                }
                b.setContentText(BoteHelper.joinAddressNames(recipients));
                b.setStyle(new NotificationCompat.BigTextStyle().bigText(bigText));
                Intent eli = new Intent(this, EmailListActivity.class);
                eli.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                PendingIntent peli = PendingIntent.getActivity(this, 0, eli, PendingIntent.FLAG_UPDATE_CURRENT);
                b.setContentIntent(peli);
        }
    } catch (PasswordException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (MessagingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (GeneralSecurityException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    nm.notify(NOTIF_ID_NEW_EMAIL, b.build());
}
Also used : Email(i2p.bote.email.Email) NotificationManager(android.app.NotificationManager) Address(javax.mail.Address) MessagingException(javax.mail.MessagingException) GeneralSecurityException(java.security.GeneralSecurityException) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) IOException(java.io.IOException) PasswordException(i2p.bote.fileencryption.PasswordException) Bitmap(android.graphics.Bitmap) NotificationCompat(android.support.v4.app.NotificationCompat) PendingIntent(android.app.PendingIntent) EmailFolder(i2p.bote.folder.EmailFolder) HashSet(java.util.HashSet)

Example 8 with PasswordException

use of i2p.bote.fileencryption.PasswordException 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 9 with PasswordException

use of i2p.bote.fileencryption.PasswordException in project i2p.i2p-bote by i2p.

the class RequirePasswordTag method doCatch.

@Override
// for javax.servlet.jsp.el.ELException
@SuppressWarnings("deprecation")
public void doCatch(Throwable t) throws Throwable {
    boolean isPasswordException = t instanceof PasswordException || t.getCause() instanceof PasswordException;
    // Special handling of javax.servlet.jsp.el.ELException thrown by Jetty (version 5.1.15, at least):
    // This exception has a separate method named getRootCause() which returns the PasswordException
    // while the regular getCause() method returns null.
    isPasswordException |= t instanceof javax.servlet.jsp.el.ELException && ((javax.servlet.jsp.el.ELException) t).getRootCause() instanceof PasswordException;
    if (isPasswordException) {
        String url;
        if (forwardUrl != null)
            url = forwardUrl;
        else {
            // if no forwardUrl is given, use the original URL
            ServletRequest request = pageContext.getRequest();
            if (!(request instanceof HttpServletRequest))
                throw new IllegalStateException("Servlet request ist not an HttpServletRequest: " + request.getClass());
            HttpServletRequest httpRequest = (HttpServletRequest) request;
            String params = httpRequest.getQueryString();
            url = httpRequest.getRequestURI();
            if (params != null)
                url += "?" + params;
            // strip the context path (usually /i2pbote)
            int contextPathLength = httpRequest.getContextPath().length();
            // add one because the context path has no slash at the end
            url = url.substring(contextPathLength + 1);
        }
        url = "password.jsp?passwordJspForwardUrl=" + url;
        pageContext.forward(url);
    } else
        throw t;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) PasswordException(i2p.bote.fileencryption.PasswordException) ServletRequest(javax.servlet.ServletRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest)

Example 10 with PasswordException

use of i2p.bote.fileencryption.PasswordException 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)

Aggregations

PasswordException (i2p.bote.fileencryption.PasswordException)26 IOException (java.io.IOException)16 GeneralSecurityException (java.security.GeneralSecurityException)15 MessagingException (javax.mail.MessagingException)11 Email (i2p.bote.email.Email)9 Bitmap (android.graphics.Bitmap)4 View (android.view.View)4 ImageView (android.widget.ImageView)4 TextView (android.widget.TextView)4 Person (i2p.bote.android.util.Person)4 Contact (i2p.bote.packet.dht.Contact)4 Part (javax.mail.Part)4 Intent (android.content.Intent)3 File (java.io.File)3 ArrayList (java.util.ArrayList)3 Address (javax.mail.Address)3 InternetAddress (javax.mail.internet.InternetAddress)3 SuppressLint (android.annotation.SuppressLint)2 IconicsDrawable (com.mikepenz.iconics.IconicsDrawable)2 ContentAttachment (i2p.bote.android.util.ContentAttachment)2