use of com.fsck.k9.mail.Address in project k-9 by k9mail.
the class MessageHeaderTest method createMessage.
private Message createMessage(Address from, Address sender) {
Message message = new MimeMessage();
message.setFrom(from);
message.setSender(sender);
return message;
}
use of com.fsck.k9.mail.Address in project k-9 by k9mail.
the class MessagingController method addErrorMessage.
private void addErrorMessage(Account account, String subject, String body) {
if (!K9.isDebug()) {
return;
}
if (!loopCatch.compareAndSet(false, true)) {
return;
}
try {
if (body == null || body.length() < 1) {
return;
}
Store localStore = account.getLocalStore();
LocalFolder localFolder = (LocalFolder) localStore.getFolder(account.getErrorFolderName());
MimeMessage message = new MimeMessage();
MimeMessageHelper.setBody(message, new TextBody(body));
message.setFlag(Flag.X_DOWNLOADED_FULL, true);
message.setSubject(subject);
long nowTime = System.currentTimeMillis();
Date nowDate = new Date(nowTime);
message.setInternalDate(nowDate);
message.addSentDate(nowDate, K9.hideTimeZone());
message.setFrom(new Address(account.getEmail(), "K9mail internal"));
localFolder.appendMessages(Collections.singletonList(message));
localFolder.clearMessagesOlderThan(nowTime - (15 * 60 * 1000));
} catch (Throwable it) {
Timber.e(it, "Could not save error message to %s", account.getErrorFolderName());
} finally {
loopCatch.set(false);
}
}
use of com.fsck.k9.mail.Address in project k-9 by k9mail.
the class MessageListAdapter method bindView.
@Override
public void bindView(View view, Context context, Cursor cursor) {
Account account = fragment.getAccountFromCursor(cursor);
String fromList = cursor.getString(SENDER_LIST_COLUMN);
String toList = cursor.getString(TO_LIST_COLUMN);
String ccList = cursor.getString(CC_LIST_COLUMN);
Address[] fromAddrs = Address.unpack(fromList);
Address[] toAddrs = Address.unpack(toList);
Address[] ccAddrs = Address.unpack(ccList);
boolean fromMe = fragment.messageHelper.toMe(account, fromAddrs);
boolean toMe = fragment.messageHelper.toMe(account, toAddrs);
boolean ccMe = fragment.messageHelper.toMe(account, ccAddrs);
CharSequence displayName = fragment.messageHelper.getDisplayName(account, fromAddrs, toAddrs);
CharSequence displayDate = DateUtils.getRelativeTimeSpanString(context, cursor.getLong(DATE_COLUMN));
Address counterpartyAddress = fetchCounterPartyAddress(fromMe, toAddrs, ccAddrs, fromAddrs);
int threadCount = (fragment.showingThreadedList) ? cursor.getInt(THREAD_COUNT_COLUMN) : 0;
String subject = MlfUtils.buildSubject(cursor.getString(SUBJECT_COLUMN), fragment.getString(R.string.general_no_subject), threadCount);
boolean read = (cursor.getInt(READ_COLUMN) == 1);
boolean flagged = (cursor.getInt(FLAGGED_COLUMN) == 1);
boolean answered = (cursor.getInt(ANSWERED_COLUMN) == 1);
boolean forwarded = (cursor.getInt(FORWARDED_COLUMN) == 1);
boolean hasAttachments = (cursor.getInt(ATTACHMENT_COUNT_COLUMN) > 0);
MessageViewHolder holder = (MessageViewHolder) view.getTag();
int maybeBoldTypeface = (read) ? Typeface.NORMAL : Typeface.BOLD;
long uniqueId = cursor.getLong(fragment.uniqueIdColumn);
boolean selected = fragment.selected.contains(uniqueId);
holder.chip.setBackgroundColor(account.getChipColor());
if (fragment.checkboxes) {
holder.selected.setChecked(selected);
}
if (fragment.stars) {
holder.flagged.setChecked(flagged);
}
holder.position = cursor.getPosition();
if (holder.contactBadge != null) {
updateContactBadge(holder, counterpartyAddress);
}
setBackgroundColor(view, selected, read);
if (fragment.activeMessage != null) {
changeBackgroundColorIfActiveMessage(cursor, account, view);
}
updateWithThreadCount(holder, threadCount);
CharSequence beforePreviewText = (fragment.senderAboveSubject) ? subject : displayName;
String sigil = recipientSigil(toMe, ccMe);
SpannableStringBuilder messageStringBuilder = new SpannableStringBuilder(sigil).append(beforePreviewText);
if (fragment.previewLines > 0) {
String preview = getPreview(cursor);
messageStringBuilder.append(" ").append(preview);
}
holder.preview.setText(messageStringBuilder, TextView.BufferType.SPANNABLE);
formatPreviewText(holder.preview, beforePreviewText, sigil);
Drawable statusHolder = buildStatusHolder(forwarded, answered);
if (holder.from != null) {
holder.from.setTypeface(Typeface.create(holder.from.getTypeface(), maybeBoldTypeface));
if (fragment.senderAboveSubject) {
holder.from.setCompoundDrawablesWithIntrinsicBounds(// left
statusHolder, // top
null, // right
hasAttachments ? mAttachmentIcon : null, // bottom
null);
holder.from.setText(displayName);
} else {
holder.from.setText(new SpannableStringBuilder(sigil).append(displayName));
}
}
if (holder.subject != null) {
if (!fragment.senderAboveSubject) {
holder.subject.setCompoundDrawablesWithIntrinsicBounds(// left
statusHolder, // top
null, // right
hasAttachments ? mAttachmentIcon : null, // bottom
null);
}
holder.subject.setTypeface(Typeface.create(holder.subject.getTypeface(), maybeBoldTypeface));
holder.subject.setText(subject);
}
holder.date.setText(displayDate);
}
use of com.fsck.k9.mail.Address in project k-9 by k9mail.
the class Contacts method markAsContacted.
/**
* Mark contacts with the provided email addresses as contacted.
*
* @param addresses Array of {@link Address} objects describing the
* contacts to be marked as contacted.
*/
public void markAsContacted(final Address[] addresses) {
//TODO: Optimize! Potentially a lot of database queries
for (final Address address : addresses) {
final Cursor c = getContactByAddress(address.getAddress());
if (c != null) {
if (c.getCount() > 0) {
c.moveToFirst();
final long personId = c.getLong(CONTACT_ID_INDEX);
ContactsContract.Contacts.markAsContacted(mContentResolver, personId);
}
c.close();
}
}
}
use of com.fsck.k9.mail.Address in project k-9 by k9mail.
the class PgpMessageBuilderTest method createDefaultPgpMessageBuilder.
private static PgpMessageBuilder createDefaultPgpMessageBuilder(OpenPgpApi openPgpApi) {
PgpMessageBuilder builder = new PgpMessageBuilder(RuntimeEnvironment.application, MessageIdGenerator.getInstance(), BoundaryGenerator.getInstance());
builder.setOpenPgpApi(openPgpApi);
Identity identity = new Identity();
identity.setName("tester");
identity.setEmail("test@example.org");
identity.setDescription("test identity");
identity.setSignatureUse(false);
builder.setSubject("subject").setSentDate(new Date()).setHideTimeZone(false).setTo(new ArrayList<Address>()).setCc(new ArrayList<Address>()).setBcc(new ArrayList<Address>()).setInReplyTo("inreplyto").setReferences("references").setRequestReadReceipt(false).setIdentity(identity).setMessageFormat(SimpleMessageFormat.TEXT).setText(TEST_MESSAGE_TEXT).setAttachments(new ArrayList<Attachment>()).setSignature("signature").setQuoteStyle(QuoteStyle.PREFIX).setQuotedTextMode(QuotedTextMode.NONE).setQuotedText("quoted text").setQuotedHtmlContent(new InsertableHtmlContent()).setReplyAfterQuote(false).setSignatureBeforeQuotedText(false).setIdentityChanged(false).setSignatureChanged(false).setCursorPosition(0).setMessageReference(null).setDraft(false);
return builder;
}
Aggregations