use of com.fsck.k9.Identity in project k-9 by k9mail.
the class MessageCompose method processMessageToReplyTo.
private void processMessageToReplyTo(MessageViewInfo messageViewInfo) throws MessagingException {
Message message = messageViewInfo.message;
if (message.getSubject() != null) {
final String subject = PREFIX.matcher(message.getSubject()).replaceFirst("");
if (!subject.toLowerCase(Locale.US).startsWith("re:")) {
subjectView.setText("Re: " + subject);
} else {
subjectView.setText(subject);
}
} else {
subjectView.setText("");
}
/*
* If a reply-to was included with the message use that, otherwise use the from
* or sender address.
*/
boolean isReplyAll = action == Action.REPLY_ALL;
recipientPresenter.initFromReplyToMessage(message, isReplyAll);
if (message.getMessageId() != null && message.getMessageId().length() > 0) {
repliedToMessageId = message.getMessageId();
String[] refs = message.getReferences();
if (refs != null && refs.length > 0) {
referencedMessageIds = TextUtils.join("", refs) + " " + repliedToMessageId;
} else {
referencedMessageIds = repliedToMessageId;
}
} else {
Timber.d("could not get Message-ID.");
}
// Quote the message and setup the UI.
quotedMessagePresenter.initFromReplyToMessage(messageViewInfo, action);
if (action == Action.REPLY || action == Action.REPLY_ALL) {
Identity useIdentity = IdentityHelper.getRecipientIdentityFromMessage(account, message);
Identity defaultIdentity = account.getIdentity(0);
if (useIdentity != defaultIdentity) {
switchToIdentity(useIdentity);
}
}
}
use of com.fsck.k9.Identity in project k-9 by k9mail.
the class ManageIdentities method onContextItemSelected.
@Override
public boolean onContextItemSelected(android.view.MenuItem item) {
AdapterContextMenuInfo menuInfo = (AdapterContextMenuInfo) item.getMenuInfo();
switch(item.getItemId()) {
case R.id.edit:
editItem(menuInfo.position);
break;
case R.id.up:
if (menuInfo.position > 0) {
Identity identity = identities.remove(menuInfo.position);
identities.add(menuInfo.position - 1, identity);
mIdentitiesChanged = true;
refreshView();
}
break;
case R.id.down:
if (menuInfo.position < identities.size() - 1) {
Identity identity = identities.remove(menuInfo.position);
identities.add(menuInfo.position + 1, identity);
mIdentitiesChanged = true;
refreshView();
}
break;
case R.id.top:
Identity identity = identities.remove(menuInfo.position);
identities.add(0, identity);
mIdentitiesChanged = true;
refreshView();
break;
case R.id.remove:
if (identities.size() > 1) {
identities.remove(menuInfo.position);
mIdentitiesChanged = true;
refreshView();
} else {
Toast.makeText(this, getString(R.string.no_removable_identity), Toast.LENGTH_LONG).show();
}
break;
}
return true;
}
use of com.fsck.k9.Identity in project k-9 by k9mail.
the class MessageBuilderTest method createIdentity.
private Identity createIdentity() {
Identity identity = new Identity();
identity.setName(TEST_IDENTITY_ADDRESS.getPersonal());
identity.setEmail(TEST_IDENTITY_ADDRESS.getAddress());
identity.setDescription("test identity");
identity.setSignatureUse(false);
return identity;
}
use of com.fsck.k9.Identity in project k-9 by k9mail.
the class OpenPgpApiHelperTest method buildUserId_withName_shouldCreateOpenPgpAccountName.
@Test
public void buildUserId_withName_shouldCreateOpenPgpAccountName() {
Identity identity = new Identity();
identity.setEmail("user@domain.com");
identity.setName("Name");
String result = OpenPgpApiHelper.buildUserId(identity);
assertEquals("Name <user@domain.com>", result);
}
use of com.fsck.k9.Identity in project k-9 by k9mail.
the class MessageBuilder method buildBody.
private void buildBody(MimeMessage message) throws MessagingException {
// Build the body.
// TODO FIXME - body can be either an HTML or Text part, depending on whether we're in
// HTML mode or not. Should probably fix this so we don't mix up html and text parts.
TextBody body = buildText(isDraft);
// text/plain part when messageFormat == MessageFormat.HTML
TextBody bodyPlain = null;
final boolean hasAttachments = !attachments.isEmpty();
if (messageFormat == SimpleMessageFormat.HTML) {
// HTML message (with alternative text part)
// This is the compiled MIME part for an HTML message.
MimeMultipart composedMimeMessage = createMimeMultipart();
composedMimeMessage.setSubType("alternative");
// Let the receiver select either the text or the HTML part.
bodyPlain = buildText(isDraft, SimpleMessageFormat.TEXT);
composedMimeMessage.addBodyPart(new MimeBodyPart(bodyPlain, "text/plain"));
composedMimeMessage.addBodyPart(new MimeBodyPart(body, "text/html"));
if (hasAttachments) {
// If we're HTML and have attachments, we have a MimeMultipart container to hold the
// whole message (mp here), of which one part is a MimeMultipart container
// (composedMimeMessage) with the user's composed messages, and subsequent parts for
// the attachments.
MimeMultipart mp = createMimeMultipart();
mp.addBodyPart(new MimeBodyPart(composedMimeMessage));
addAttachmentsToMessage(mp);
MimeMessageHelper.setBody(message, mp);
} else {
// If no attachments, our multipart/alternative part is the only one we need.
MimeMessageHelper.setBody(message, composedMimeMessage);
}
} else if (messageFormat == SimpleMessageFormat.TEXT) {
// Text-only message.
if (hasAttachments) {
MimeMultipart mp = createMimeMultipart();
mp.addBodyPart(new MimeBodyPart(body, "text/plain"));
addAttachmentsToMessage(mp);
MimeMessageHelper.setBody(message, mp);
} else {
// No attachments to include, just stick the text body in the message and call it good.
MimeMessageHelper.setBody(message, body);
}
}
// If this is a draft, add metadata for thawing.
if (isDraft) {
// Add the identity to the message.
message.addHeader(K9.IDENTITY_HEADER, buildIdentityHeader(body, bodyPlain));
}
}
Aggregations