Search in sources :

Example 1 with ConversionResult

use of com.zegoggles.smssync.mail.ConversionResult in project sms-backup-plus by jberkel.

the class BackupTask method backupCursors.

private BackupState backupCursors(BackupCursors cursors, BackupImapStore store, BackupType backupType, int itemsToSync) throws MessagingException {
    Log.i(TAG, String.format(Locale.ENGLISH, "Starting backup (%d messages)", itemsToSync));
    publish(LOGIN);
    store.checkSettings();
    try {
        publish(CALC);
        int backedUpItems = 0;
        while (!isCancelled() && cursors.hasNext()) {
            BackupCursors.CursorAndType cursor = cursors.next();
            if (LOCAL_LOGV)
                Log.v(TAG, "backing up: " + cursor);
            ConversionResult result = converter.convertMessages(cursor.cursor, cursor.type);
            if (!result.isEmpty()) {
                List<Message> messages = result.getMessages();
                if (LOCAL_LOGV) {
                    Log.v(TAG, String.format(Locale.ENGLISH, "sending %d %s message(s) to server.", messages.size(), cursor.type));
                }
                store.getFolder(cursor.type, preferences.getDataTypePreferences()).appendMessages(messages);
                if (cursor.type == CALLLOG && calendarSyncer != null) {
                    calendarSyncer.syncCalendar(result);
                }
                preferences.getDataTypePreferences().setMaxSyncedDate(cursor.type, result.getMaxDate());
                backedUpItems += messages.size();
            } else {
                Log.w(TAG, "no messages converted");
                itemsToSync -= 1;
            }
            publishProgress(new BackupState(BACKUP, backedUpItems, itemsToSync, backupType, cursor.type, null));
        }
        return new BackupState(FINISHED_BACKUP, backedUpItems, itemsToSync, backupType, null, null);
    } finally {
        store.closeFolders();
    }
}
Also used : BackupState(com.zegoggles.smssync.service.state.BackupState) ConversionResult(com.zegoggles.smssync.mail.ConversionResult) Message(com.fsck.k9.mail.Message)

Example 2 with ConversionResult

use of com.zegoggles.smssync.mail.ConversionResult in project sms-backup-plus by jberkel.

the class CalendarSyncerTest method shouldSyncCalendar.

@Test
public void shouldSyncCalendar() throws Exception {
    ConversionResult result = new ConversionResult(DataType.CALLLOG);
    final String NUMBER = "12345";
    final String NAME = "Foo";
    final int DURATION = 10;
    final int TYPE = 1;
    Date callTime = new Date();
    result.add(new MimeMessage(), message(DURATION, TYPE, NUMBER, callTime));
    result.add(new MimeMessage(), message(DURATION, TYPE, NUMBER, callTime));
    when(callFormatter.callTypeString(TYPE, NAME)).thenReturn("title1");
    when(callFormatter.formatForCalendar(TYPE, NUMBER, DURATION)).thenReturn("title2");
    when(personLookup.lookupPerson(NUMBER)).thenReturn(new PersonRecord(1, NAME, "foo@bar", NUMBER));
    syncer.syncCalendar(result);
    verify(accessor, times(2)).addEntry(eq(CALENDAR_ID), eq(callTime), eq(DURATION), eq("title1"), eq("title2"));
}
Also used : ConversionResult(com.zegoggles.smssync.mail.ConversionResult) MimeMessage(com.fsck.k9.mail.internet.MimeMessage) PersonRecord(com.zegoggles.smssync.mail.PersonRecord) Date(java.util.Date) Test(org.junit.Test)

Aggregations

ConversionResult (com.zegoggles.smssync.mail.ConversionResult)2 Message (com.fsck.k9.mail.Message)1 MimeMessage (com.fsck.k9.mail.internet.MimeMessage)1 PersonRecord (com.zegoggles.smssync.mail.PersonRecord)1 BackupState (com.zegoggles.smssync.service.state.BackupState)1 Date (java.util.Date)1 Test (org.junit.Test)1