@Before
 public void setUp() throws Exception {
   initMocks(this);
   BinaryTempFileBody.setTempDirectory(Robolectric.application.getCacheDir());
   messageConverter =
       new MessageConverter(
           Robolectric.application, preferences, "*****@*****.**", personLookup, contactAccessor);
 }
Example #2
0
File: K9.java Project: klonikar/k-9
  @Override
  public void onCreate() {
    if (K9.DEVELOPER_MODE) {
      StrictMode.enableDefaults();
    }

    PRNGFixes.apply();

    super.onCreate();
    app = this;

    sIsDebuggable = ((getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0);
    K9MailLib.setDebugStatus(
        new K9MailLib.DebugStatus() {
          @Override
          public boolean enabled() {
            return DEBUG;
          }

          @Override
          public boolean debugSensitive() {
            return DEBUG_SENSITIVE;
          }
        });

    checkCachedDatabaseVersion();

    Preferences prefs = Preferences.getPreferences(this);
    loadPrefs(prefs);

    /*
     * We have to give MimeMessage a temp directory because File.createTempFile(String, String)
     * doesn't work in Android and MimeMessage does not have access to a Context.
     */
    BinaryTempFileBody.setTempDirectory(getCacheDir());

    LocalKeyStore.setKeyStoreLocation(getDir("KeyStore", MODE_PRIVATE).toString());

    /*
     * Enable background sync of messages
     */

    setServicesEnabled(this);
    registerReceivers();

    MessagingController.getInstance(this)
        .addListener(
            new MessagingListener() {
              private void broadcastIntent(
                  String action, Account account, String folder, Message message) {
                try {
                  Uri uri =
                      Uri.parse(
                          "email://messages/"
                              + account.getAccountNumber()
                              + "/"
                              + Uri.encode(folder)
                              + "/"
                              + Uri.encode(message.getUid()));
                  Intent intent = new Intent(action, uri);
                  intent.putExtra(K9.Intents.EmailReceived.EXTRA_ACCOUNT, account.getDescription());
                  intent.putExtra(K9.Intents.EmailReceived.EXTRA_FOLDER, folder);
                  intent.putExtra(K9.Intents.EmailReceived.EXTRA_SENT_DATE, message.getSentDate());
                  intent.putExtra(
                      K9.Intents.EmailReceived.EXTRA_FROM, Address.toString(message.getFrom()));
                  intent.putExtra(
                      K9.Intents.EmailReceived.EXTRA_TO,
                      Address.toString(message.getRecipients(Message.RecipientType.TO)));
                  intent.putExtra(
                      K9.Intents.EmailReceived.EXTRA_CC,
                      Address.toString(message.getRecipients(Message.RecipientType.CC)));
                  intent.putExtra(
                      K9.Intents.EmailReceived.EXTRA_BCC,
                      Address.toString(message.getRecipients(Message.RecipientType.BCC)));
                  intent.putExtra(K9.Intents.EmailReceived.EXTRA_SUBJECT, message.getSubject());
                  intent.putExtra(
                      K9.Intents.EmailReceived.EXTRA_FROM_SELF,
                      account.isAnIdentity(message.getFrom()));
                  K9.this.sendBroadcast(intent);
                  if (K9.DEBUG)
                    Log.d(
                        K9.LOG_TAG,
                        "Broadcasted: action="
                            + action
                            + " account="
                            + account.getDescription()
                            + " folder="
                            + folder
                            + " message uid="
                            + message.getUid());

                } catch (MessagingException e) {
                  Log.w(
                      K9.LOG_TAG,
                      "Error: action="
                          + action
                          + " account="
                          + account.getDescription()
                          + " folder="
                          + folder
                          + " message uid="
                          + message.getUid());
                }
              }

              private void updateUnreadWidget() {
                try {
                  UnreadWidgetProvider.updateUnreadCount(K9.this);
                } catch (Exception e) {
                  if (K9.DEBUG) {
                    Log.e(LOG_TAG, "Error while updating unread widget(s)", e);
                  }
                }
              }

              @Override
              public void synchronizeMailboxRemovedMessage(
                  Account account, String folder, Message message) {
                broadcastIntent(
                    K9.Intents.EmailReceived.ACTION_EMAIL_DELETED, account, folder, message);
                updateUnreadWidget();
              }

              @Override
              public void messageDeleted(Account account, String folder, Message message) {
                broadcastIntent(
                    K9.Intents.EmailReceived.ACTION_EMAIL_DELETED, account, folder, message);
                updateUnreadWidget();
              }

              @Override
              public void synchronizeMailboxNewMessage(
                  Account account, String folder, Message message) {
                broadcastIntent(
                    K9.Intents.EmailReceived.ACTION_EMAIL_RECEIVED, account, folder, message);
                updateUnreadWidget();
              }

              @Override
              public void folderStatusChanged(
                  Account account, String folderName, int unreadMessageCount) {

                updateUnreadWidget();

                // let observers know a change occurred
                Intent intent = new Intent(K9.Intents.EmailReceived.ACTION_REFRESH_OBSERVER, null);
                intent.putExtra(K9.Intents.EmailReceived.EXTRA_ACCOUNT, account.getDescription());
                intent.putExtra(K9.Intents.EmailReceived.EXTRA_FOLDER, folderName);
                K9.this.sendBroadcast(intent);
              }
            });

    notifyObservers();
  }
Example #3
0
File: K9.java Project: kamilk/k-9
  @Override
  public void onCreate() {
    maybeSetupStrictMode();
    super.onCreate();
    app = this;

    galleryBuggy = checkForBuggyGallery();

    Preferences prefs = Preferences.getPreferences(this);
    SharedPreferences sprefs = prefs.getPreferences();
    DEBUG = sprefs.getBoolean("enableDebugLogging", false);
    DEBUG_SENSITIVE = sprefs.getBoolean("enableSensitiveLogging", false);
    mAnimations = sprefs.getBoolean("animations", true);
    mGesturesEnabled = sprefs.getBoolean("gesturesEnabled", true);
    mUseVolumeKeysForNavigation = sprefs.getBoolean("useVolumeKeysForNavigation", false);
    mUseVolumeKeysForListNavigation = sprefs.getBoolean("useVolumeKeysForListNavigation", false);
    mManageBack = sprefs.getBoolean("manageBack", false);
    mStartIntegratedInbox = sprefs.getBoolean("startIntegratedInbox", false);
    mMeasureAccounts = sprefs.getBoolean("measureAccounts", true);
    mCountSearchMessages = sprefs.getBoolean("countSearchMessages", true);
    mHideSpecialAccounts = sprefs.getBoolean("hideSpecialAccounts", false);
    mMessageListStars = sprefs.getBoolean("messageListStars", true);
    mMessageListCheckboxes = sprefs.getBoolean("messageListCheckboxes", false);
    mMessageListTouchable = sprefs.getBoolean("messageListTouchable", false);
    mMessageListPreviewLines = sprefs.getInt("messageListPreviewLines", 2);

    mMobileOptimizedLayout = sprefs.getBoolean("mobileOptimizedLayout", false);
    mZoomControlsEnabled = sprefs.getBoolean("zoomControlsEnabled", false);

    mQuietTimeEnabled = sprefs.getBoolean("quietTimeEnabled", false);
    mQuietTimeStarts = sprefs.getString("quietTimeStarts", "21:00");
    mQuietTimeEnds = sprefs.getString("quietTimeEnds", "7:00");

    mShowCorrespondentNames = sprefs.getBoolean("showCorrespondentNames", true);
    mShowContactName = sprefs.getBoolean("showContactName", false);
    mChangeContactNameColor = sprefs.getBoolean("changeRegisteredNameColor", false);
    mContactNameColor = sprefs.getInt("registeredNameColor", 0xff00008f);
    mMessageViewFixedWidthFont = sprefs.getBoolean("messageViewFixedWidthFont", false);
    mMessageViewReturnToList = sprefs.getBoolean("messageViewReturnToList", false);

    useGalleryBugWorkaround = sprefs.getBoolean("useGalleryBugWorkaround", K9.isGalleryBuggy());

    mConfirmDelete = sprefs.getBoolean("confirmDelete", false);

    mKeyguardPrivacy = sprefs.getBoolean("keyguardPrivacy", false);

    compactLayouts = sprefs.getBoolean("compactLayouts", false);

    fontSizes.load(sprefs);

    try {
      setBackgroundOps(
          BACKGROUND_OPS.valueOf(sprefs.getString("backgroundOperations", "WHEN_CHECKED")));
    } catch (Exception e) {
      setBackgroundOps(BACKGROUND_OPS.WHEN_CHECKED);
    }

    K9.setK9Language(sprefs.getString("language", ""));
    K9.setK9Theme(sprefs.getInt("theme", android.R.style.Theme_Light));

    /*
     * We have to give MimeMessage a temp directory because File.createTempFile(String, String)
     * doesn't work in Android and MimeMessage does not have access to a Context.
     */
    BinaryTempFileBody.setTempDirectory(getCacheDir());

    /*
     * Enable background sync of messages
     */

    setServicesEnabled(this);
    registerReceivers();

    MessagingController.getInstance(this)
        .addListener(
            new MessagingListener() {
              private void broadcastIntent(
                  String action, Account account, String folder, Message message) {
                try {
                  Uri uri =
                      Uri.parse(
                          "email://messages/"
                              + account.getAccountNumber()
                              + "/"
                              + Uri.encode(folder)
                              + "/"
                              + Uri.encode(message.getUid()));
                  Intent intent = new Intent(action, uri);
                  intent.putExtra(K9.Intents.EmailReceived.EXTRA_ACCOUNT, account.getDescription());
                  intent.putExtra(K9.Intents.EmailReceived.EXTRA_FOLDER, folder);
                  intent.putExtra(K9.Intents.EmailReceived.EXTRA_SENT_DATE, message.getSentDate());
                  intent.putExtra(
                      K9.Intents.EmailReceived.EXTRA_FROM, Address.toString(message.getFrom()));
                  intent.putExtra(
                      K9.Intents.EmailReceived.EXTRA_TO,
                      Address.toString(message.getRecipients(Message.RecipientType.TO)));
                  intent.putExtra(
                      K9.Intents.EmailReceived.EXTRA_CC,
                      Address.toString(message.getRecipients(Message.RecipientType.CC)));
                  intent.putExtra(
                      K9.Intents.EmailReceived.EXTRA_BCC,
                      Address.toString(message.getRecipients(Message.RecipientType.BCC)));
                  intent.putExtra(K9.Intents.EmailReceived.EXTRA_SUBJECT, message.getSubject());
                  intent.putExtra(
                      K9.Intents.EmailReceived.EXTRA_FROM_SELF,
                      account.isAnIdentity(message.getFrom()));
                  K9.this.sendBroadcast(intent);
                  if (K9.DEBUG)
                    Log.d(
                        K9.LOG_TAG,
                        "Broadcasted: action="
                            + action
                            + " account="
                            + account.getDescription()
                            + " folder="
                            + folder
                            + " message uid="
                            + message.getUid());

                } catch (MessagingException e) {
                  Log.w(
                      K9.LOG_TAG,
                      "Error: action="
                          + action
                          + " account="
                          + account.getDescription()
                          + " folder="
                          + folder
                          + " message uid="
                          + message.getUid());
                }
              }

              @Override
              public void synchronizeMailboxRemovedMessage(
                  Account account, String folder, Message message) {
                broadcastIntent(
                    K9.Intents.EmailReceived.ACTION_EMAIL_DELETED, account, folder, message);
              }

              @Override
              public void messageDeleted(Account account, String folder, Message message) {
                broadcastIntent(
                    K9.Intents.EmailReceived.ACTION_EMAIL_DELETED, account, folder, message);
              }

              @Override
              public void synchronizeMailboxNewMessage(
                  Account account, String folder, Message message) {
                broadcastIntent(
                    K9.Intents.EmailReceived.ACTION_EMAIL_RECEIVED, account, folder, message);
              }

              @Override
              public void searchStats(final AccountStats stats) {
                // let observers know a fetch occured
                K9.this.sendBroadcast(
                    new Intent(K9.Intents.EmailReceived.ACTION_REFRESH_OBSERVER, null));
              }
            });

    notifyObservers();
  }