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();
}
}
}
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());
}
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>";
}
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;
}
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;
}
Aggregations