Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ enum class SortType(val isDefaultAscending: Boolean) {
SORT_UNREAD(true),
SORT_FLAGGED(true),
SORT_ATTACHMENT(true),
SORT_SIZE(false),
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const val DISPLAY_SETTINGS_DEFAULT_SHOULD_SHOW_SETUP_ARCHIVE_FOLDER_DIALOG = tru
const val DISPLAY_SETTINGS_DEFAULT_IS_MESSAGE_LIST_SENDER_ABOVE_SUBJECT = false
const val DISPLAY_SETTINGS_DEFAULT_IS_SHOW_CONTACT_NAME = false
const val DISPLAY_SETTINGS_DEFAULT_IS_SHOW_CONTACT_PICTURE = true
const val DISPLAY_SETTINGS_DEFAULT_IS_SHOW_MESSAGE_SIZE = false
const val DISPLAY_SETTINGS_DEFAULT_IS_CHANGE_CONTACT_NAME_COLOR = true
const val DISPLAY_SETTINGS_DEFAULT_IS_COLORIZE_MISSING_CONTACT_PICTURE = false
const val DISPLAY_SETTINGS_DEFAULT_IS_USE_BACKGROUND_AS_INDICATOR = false
Expand All @@ -44,6 +45,7 @@ data class DisplaySettings(
val isMessageListSenderAboveSubject: Boolean = DISPLAY_SETTINGS_DEFAULT_IS_MESSAGE_LIST_SENDER_ABOVE_SUBJECT,
val isShowContactName: Boolean = DISPLAY_SETTINGS_DEFAULT_IS_SHOW_CONTACT_NAME,
val isShowContactPicture: Boolean = DISPLAY_SETTINGS_DEFAULT_IS_SHOW_CONTACT_PICTURE,
val isShowMessageSize: Boolean = DISPLAY_SETTINGS_DEFAULT_IS_SHOW_MESSAGE_SIZE,
val isChangeContactNameColor: Boolean = DISPLAY_SETTINGS_DEFAULT_IS_CHANGE_CONTACT_NAME_COLOR,
val isColorizeMissingContactPictures: Boolean = DISPLAY_SETTINGS_DEFAULT_IS_COLORIZE_MISSING_CONTACT_PICTURE,
val isUseBackgroundAsUnreadIndicator: Boolean = DISPLAY_SETTINGS_DEFAULT_IS_USE_BACKGROUND_AS_INDICATOR,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const val KEY_MESSAGE_VIEW_FIXED_WIDTH_FONT = "messageViewFixedWidthFont"
const val KEY_AUTO_FIT_WIDTH = "autofitWidth"
const val KEY_MESSAGE_LIST_SENDER_ABOVE_SUBJECT = "messageListSenderAboveSubject"
const val KEY_SHOW_CONTACT_PICTURE = "showContactPicture"
const val KEY_SHOW_MESSAGE_SIZE = "showMessageSize"
const val KEY_APP_LANGUAGE = "language"
const val KEY_SPLIT_VIEW_MODE = "splitViewMode"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ class DefaultDisplaySettingsPreferenceManager(
KEY_SHOW_CONTACT_PICTURE,
DISPLAY_SETTINGS_DEFAULT_IS_SHOW_CONTACT_PICTURE,
),
isShowMessageSize = storage.getBoolean(
KEY_SHOW_MESSAGE_SIZE,
DISPLAY_SETTINGS_DEFAULT_IS_SHOW_MESSAGE_SIZE,
),
appLanguage = storage.getStringOrDefault(
KEY_APP_LANGUAGE,
DISPLAY_SETTINGS_DEFAULT_APP_LANGUAGE,
Expand Down Expand Up @@ -176,6 +180,10 @@ class DefaultDisplaySettingsPreferenceManager(
KEY_SHOW_CONTACT_PICTURE,
config.isShowContactPicture,
)
storageEditor.putBoolean(
KEY_SHOW_MESSAGE_SIZE,
config.isShowMessageSize,
)
storageEditor.putBoolean(
KEY_USE_BACKGROUND_AS_UNREAD_INDICATOR,
config.isUseBackgroundAsUnreadIndicator,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ private fun generateMessageListItems(): ImmutableList<MessageListItem> {
preview = "Preview 1",
color = Color.BLUE,
isRead = false,
size = 1L,
),
generateMessageListItem(
displayName = "Bob",
Expand All @@ -46,6 +47,7 @@ private fun generateMessageListItems(): ImmutableList<MessageListItem> {
preview = "Preview 2",
color = Color.RED,
isRead = true,
size = 2L * 1024L,
),
generateMessageListItem(
displayName = "Charlie",
Expand All @@ -54,6 +56,7 @@ private fun generateMessageListItems(): ImmutableList<MessageListItem> {
preview = "Preview 3",
color = Color.RED,
isRead = false,
size = 3L * 1024L * 1024L,
),
)
}
Expand All @@ -65,6 +68,7 @@ private fun generateMessageListItem(
preview: String,
color: Int,
isRead: Boolean,
size: Long,
): MessageListItem {
return MessageListItem(
displayName = displayName,
Expand All @@ -82,5 +86,6 @@ private fun generateMessageListItem(
sortInternalDate = 0,
sortIsStarred = false,
sortDatabaseId = 0,
sortSize = size,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ internal data class MessageListItem(
val sortInternalDate: Long,
val sortIsStarred: Boolean,
val sortDatabaseId: Long,
val sortSize: Long,
)
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ internal class MessageListItemMapper(
sortInternalDate = message.internalDate,
sortIsStarred = message.isStarred,
sortDatabaseId = message.id,
sortSize = message.size,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ internal class MessageListLoader(
SortType.SORT_SUBJECT -> "${MessageColumns.SUBJECT} COLLATE NOCASE"
SortType.SORT_UNREAD -> MessageColumns.READ
SortType.SORT_DATE -> MessageColumns.DATE
SortType.SORT_SIZE -> MessageColumns.SIZE
}

val sortDirection = if (config.sortAscending) " ASC" else " DESC"
Expand Down Expand Up @@ -122,6 +123,11 @@ internal class MessageListLoader(
compareBy<MessageListItem>(!config.sortAscending) { it.hasAttachments }
.thenByDate(config)
}

SortType.SORT_SIZE -> {
compareBy<MessageListItem>(config.sortAscending) { it.sortSize }
.thenByDate(config)
}
}.thenByDescending { it.sortDatabaseId }

return this.sortedWith(comparator)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ internal data class MessageListItem(
val sortInternalDate: Long,
val sortIsStarred: Boolean,
val sortDatabaseId: Long,
val sortSize: Long,
)
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ internal class MessageListItemMapper(
sortInternalDate = message.internalDate,
sortIsStarred = message.isStarred,
sortDatabaseId = message.id,
sortSize = message.size,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ internal class MessageListLoader(
SortType.SORT_SUBJECT -> "${MessageColumns.SUBJECT} COLLATE NOCASE"
SortType.SORT_UNREAD -> MessageColumns.READ
SortType.SORT_DATE -> MessageColumns.DATE
else -> MessageColumns.DATE
SortType.SORT_SIZE -> MessageColumns.SIZE
}

val sortDirection = if (config.sortAscending) " ASC" else " DESC"
Expand Down Expand Up @@ -123,6 +123,11 @@ internal class MessageListLoader(
compareBy<MessageListItem>(!config.sortAscending) { it.hasAttachments }
.thenByDate(config)
}

SortType.SORT_SIZE -> {
compareBy<MessageListItem>(config.sortAscending) { it.sortSize }
.thenByDate(config)
}
}.thenByDescending { it.sortDatabaseId }

return this.sortedWith(comparator)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public class LocalMessage extends MimeMessage {
private boolean headerNeedsUpdating = false;
private LocalFolder mFolder;
private GeneralSettingsManager generalSettingsManager;
private long size;

LocalMessage(LocalStore localStore, String uid, LocalFolder folder, GeneralSettingsManager generalSettingsManager) {
this.localStore = localStore;
Expand Down Expand Up @@ -137,6 +138,8 @@ void populateFromGetMessageCursor(Cursor cursor) throws MessagingException {
Log.d("No headers available for this message!");
}

this.size = cursor.isNull(LocalStore.MSG_INDEX_SIZE) ? 0 : cursor.getLong(LocalStore.MSG_INDEX_SIZE);

headerNeedsUpdating = false;
}

Expand Down Expand Up @@ -453,4 +456,8 @@ public int hashCode() {
private String getAccountUuid() {
return getAccount().getUuid();
}

public long getSize() {
return size;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

package com.fsck.k9.mailstore;


Expand Down Expand Up @@ -76,7 +75,7 @@ public class LocalStore {
"subject, sender_list, date, uid, flags, messages.id, to_list, cc_list, " +
"bcc_list, reply_to_list, attachment_count, internal_date, messages.message_id, " +
"folder_id, preview, threads.id, threads.root, deleted, read, flagged, answered, " +
"forwarded, message_part_id, messages.mime_type, preview_type, header ";
"forwarded, message_part_id, messages.mime_type, preview_type, header, size ";

static final int MSG_INDEX_SUBJECT = 0;
static final int MSG_INDEX_SENDER_LIST = 1;
Expand Down Expand Up @@ -104,9 +103,10 @@ public class LocalStore {
static final int MSG_INDEX_MIME_TYPE = 23;
static final int MSG_INDEX_PREVIEW_TYPE = 24;
static final int MSG_INDEX_HEADER_DATA = 25;
static final int MSG_INDEX_SIZE = 26;

static final int MSG_INDEX_NOTIFICATION_ID = 26;
static final int MSG_INDEX_NOTIFICATION_TIMESTAMP = 27;
static final int MSG_INDEX_NOTIFICATION_ID = 27;
static final int MSG_INDEX_NOTIFICATION_TIMESTAMP = 28;

static final String GET_FOLDER_COLS =
"folders.id, name, visible_limit, last_updated, status, " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ object MessageColumns {
const val FLAGGED = "flagged"
const val ANSWERED = "answered"
const val FORWARDED = "forwarded"
const val SIZE = "size"
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class SaveMessageDataCreator(
previewResult = encryptionResult.previewResult,
textForSearchIndex = encryptionResult.textForSearchIndex,
encryptionType = encryptionResult.encryptionType,
size = message.size,
)
} else {
SaveMessageData(
Expand All @@ -48,6 +49,7 @@ class SaveMessageDataCreator(
previewResult = messagePreviewCreator.createPreview(message),
textForSearchIndex = messageFulltextCreator.createFulltext(message),
encryptionType = null,
size = message.size,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,7 @@ class MessageListRepositoryTest {
override val hasAttachments = false
override val threadRoot = message.threadRoot
override val threadCount = 0
override val size = 1024L
},
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ interface MessageDetailsAccessor {
val hasAttachments: Boolean
val threadRoot: Long
val threadCount: Int
val size: Long
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ data class SaveMessageData(
val previewResult: PreviewResult,
val textForSearchIndex: String? = null,
val encryptionType: String?,
val size: Long? = null,
)
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@


class StoreSchemaDefinition implements SchemaDefinition {
static final int DB_VERSION = 88;
static final int DB_VERSION = 89;

private final MigrationsHelper migrationsHelper;

Expand Down Expand Up @@ -141,7 +141,8 @@ private static void dbCreateDatabaseFromScratch(SQLiteDatabase db) {
"forwarded INTEGER default 0, " +
"message_part_id INTEGER," +
"encryption_type TEXT," +
"new_message INTEGER DEFAULT 0" +
"new_message INTEGER DEFAULT 0," +
"size INTEGER" +
")");

db.execSQL("DROP INDEX IF EXISTS new_messages");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ SELECT
answered,
forwarded,
attachment_count,
root
root,
size
FROM messages
JOIN threads ON (threads.message_id = messages.id)
LEFT JOIN FOLDERS ON (folders.id = messages.folder_id)
Expand Down Expand Up @@ -94,7 +95,8 @@ SELECT
aggregated.forwarded AS forwarded,
aggregated.attachment_count AS attachment_count,
root,
aggregated.thread_count AS thread_count
aggregated.thread_count AS thread_count,
messages.size AS size
FROM (
SELECT
threads.root AS thread_root,
Expand Down Expand Up @@ -166,7 +168,8 @@ SELECT
answered,
forwarded,
attachment_count,
root
root,
size
FROM threads
JOIN messages ON (messages.id = threads.message_id)
LEFT JOIN FOLDERS ON (folders.id = messages.folder_id)
Expand Down Expand Up @@ -233,6 +236,17 @@ private class CursorMessageAccessor(val cursor: Cursor, val includesThreadCount:
get() = cursor.getLong(16)
override val threadCount: Int
get() = if (includesThreadCount) cursor.getInt(17) else 0
override val size: Long
get() = if (includesThreadCount) {
cursor.getLong(SIZE_COLUMN_INDEX_WITH_THREAD)
} else {
cursor.getLong(SIZE_COLUMN_INDEX_WITHOUT_THREAD)
}

companion object {
private const val SIZE_COLUMN_INDEX_WITH_THREAD = 18
private const val SIZE_COLUMN_INDEX_WITHOUT_THREAD = 17
}
}

private val AGGREGATED_MESSAGES_COLUMNS = arrayOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,7 @@ internal class SaveMessageOperations(
put("message_id", message.messageId)
put("mime_type", message.mimeType)
put("encryption_type", messageData.encryptionType)
put("size", messageData.size)

val previewResult = messageData.previewResult
put("preview_type", previewResult.previewType.toDatabaseValue())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.fsck.k9.storage.migrations

import android.database.sqlite.SQLiteDatabase

internal class MigrationTo89(private val db: SQLiteDatabase) {
fun addMessageSizeColumn() {
db.execSQL("ALTER TABLE messages ADD size INTEGER")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,6 @@ object Migrations {
if (oldVersion < 86) MigrationTo86(db, migrationsHelper).addFoldersPushEnabledColumn()
if (oldVersion < 87) MigrationTo87(db, migrationsHelper).addFoldersSyncEnabledColumn()
if (oldVersion < 88) MigrationTo88(db, migrationsHelper).addFoldersVisibleColumn()
if (oldVersion < 89) MigrationTo89(db).addMessageSizeColumn()
}
}
Loading