use of i2p.bote.email.Attachment in project i2p.i2p-bote by i2p.
the class NewEmailFragment method sendEmail.
private boolean sendEmail() {
Email email = new Email(I2PBote.getInstance().getConfiguration().getIncludeSentTime());
try {
// Set sender
EmailIdentity sender = (EmailIdentity) mSpinner.getSelectedItem();
InternetAddress ia = new InternetAddress(sender == null ? "Anonymous" : BoteHelper.getNameAndDestination(sender.getKey()));
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);
for (Object obj : mTo.getObjects()) {
Person person = (Person) obj;
email.addRecipient(Message.RecipientType.TO, new InternetAddress(person.getAddress(), person.getName()));
}
if (mMoreVisible) {
for (Object obj : mCc.getObjects()) {
Person person = (Person) obj;
email.addRecipient(Message.RecipientType.CC, new InternetAddress(person.getAddress(), person.getName()));
}
for (Object obj : mBcc.getObjects()) {
Person person = (Person) obj;
email.addRecipient(Message.RecipientType.BCC, new InternetAddress(person.getAddress(), person.getName()));
}
}
// Check that we have someone to send to
Address[] rcpts = email.getAllRecipients();
if (rcpts == null || rcpts.length == 0) {
// No recipients
mTo.setError(getActivity().getString(R.string.add_one_recipient));
mTo.requestFocus();
return false;
} else {
mTo.setError(null);
}
email.setSubject(mSubject.getText().toString(), "UTF-8");
// Extract the attachments
List<Attachment> attachments = new ArrayList<Attachment>();
for (int i = 0; i < mAttachments.getChildCount(); i++) {
View v = mAttachments.getChildAt(i);
// Warning views don't have tags set
if (v.getTag() != null)
attachments.add((Attachment) v.getTag());
}
// Set the text and add attachments
email.setContent(mContent.getText().toString(), attachments);
// Cache the fact that we sent this email
BoteHelper.setEmailSent(email, true);
// Send the email
I2PBote.getInstance().sendEmail(email);
// Clean up attachments
for (Attachment attachment : attachments) {
if (!attachment.clean())
Log.e(Constants.ANDROID_LOG_TAG, "Can't clean up attachment: <" + attachment + ">");
}
return true;
} catch (PasswordException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (AddressException 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();
}
return false;
}
use of i2p.bote.email.Attachment 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.Attachment 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);
}
Aggregations