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