예제 #1
0
  private String getType(String dbName, String id, String format) {
    String type;
    if (FORMAT_THUMBNAIL.equals(format)) {
      type = "image/png";
    } else {
      final Account account = Preferences.getPreferences(getContext()).getAccount(dbName);

      try {
        final LocalStore localStore = LocalStore.getLocalInstance(account, K9.app);

        AttachmentInfo attachmentInfo = localStore.getAttachmentInfo(id);
        if (FORMAT_VIEW.equals(format)) {
          type = MimeUtility.getMimeTypeForViewing(attachmentInfo.type, attachmentInfo.name);
        } else {
          // When accessing the "raw" message we deliver the original
          // MIME type.
          type = attachmentInfo.type;
        }
      } catch (MessagingException e) {
        Log.e(K9.LOG_TAG, "Unable to retrieve LocalStore for " + account, e);
        type = null;
      }
    }

    return type;
  }
예제 #2
0
  private LockableDatabase getDatabase(Account account) {
    LocalStore localStore;
    try {
      localStore = account.getLocalStore();
    } catch (MessagingException e) {
      throw new RuntimeException("Couldn't get LocalStore", e);
    }

    return localStore.getDatabase();
  }
예제 #3
0
  private static long getFolderId(Account account, String folderName) {
    long folderId = 0;
    try {
      LocalStore localStore = account.getLocalStore();
      LocalFolder folder = localStore.getFolder(folderName);
      folder.open(OpenMode.READ_ONLY);
      folderId = folder.getId();
    } catch (MessagingException e) {
      // FIXME
      e.printStackTrace();
    }

    return folderId;
  }
예제 #4
0
  @Override
  public int delete(Uri uri, String selection, String[] selectionArgs) {
    if (K9.app == null) {
      return 0;
    }

    if (K9.DEBUG) {
      Log.v(K9.LOG_TAG, "MessageProvider/delete: " + uri);
    }

    // Note: can only delete a message

    List<String> segments = null;
    int accountId = -1;
    String folderName = null;
    String msgUid = null;

    segments = uri.getPathSegments();
    accountId = Integer.parseInt(segments.get(1));
    folderName = segments.get(2);
    msgUid = segments.get(3);

    // get account
    Account myAccount = null;
    for (Account account : Preferences.getPreferences(getContext()).getAccounts()) {
      if (account.getAccountNumber() == accountId) {
        myAccount = account;
        if (!account.isAvailable(getContext())) {
          Log.w(K9.LOG_TAG, "not deleting messages because account is unavailable at the moment");
          return 0;
        }
      }
    }

    // get localstore parameter
    Message msg = null;
    try {
      Folder lf = LocalStore.getLocalInstance(myAccount, K9.app).getFolder(folderName);
      int msgCount = lf.getMessageCount();
      if (K9.DEBUG) {
        Log.d(K9.LOG_TAG, "folder msg count = " + msgCount);
      }
      msg = lf.getMessage(msgUid);
    } catch (MessagingException e) {
      Log.e(K9.LOG_TAG, "Unable to retrieve message", e);
    }

    // launch command to delete the message
    if ((myAccount != null) && (msg != null)) {
      MessagingController.getInstance(K9.app).deleteMessages(new Message[] {msg}, null);
    }

    // FIXME return the actual number of deleted messages
    return 0;
  }
예제 #5
0
  @Override
  public Cursor query(
      Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {

    String[] columnNames = (projection == null) ? DEFAULT_PROJECTION : projection;

    List<String> segments = uri.getPathSegments();
    String dbName = segments.get(0);
    String id = segments.get(1);

    // Versions of K-9 before 3.400 had a database name here, not an
    // account UID, so implement a bit of backcompat
    if (dbName.endsWith(".db")) {
      dbName = dbName.substring(0, dbName.length() - 3);
    }

    final AttachmentInfo attachmentInfo;
    try {
      final Account account = Preferences.getPreferences(getContext()).getAccount(dbName);
      attachmentInfo = LocalStore.getLocalInstance(account, K9.app).getAttachmentInfo(id);
    } catch (MessagingException e) {
      Log.e(K9.LOG_TAG, "Unable to retrieve attachment info from local store for ID: " + id, e);
      return null;
    }

    if (attachmentInfo == null) {
      if (K9.DEBUG) {
        Log.d(K9.LOG_TAG, "No attachment info for ID: " + id);
      }
      return null;
    }

    MatrixCursor ret = new MatrixCursor(columnNames);
    Object[] values = new Object[columnNames.length];
    for (int i = 0, count = columnNames.length; i < count; i++) {
      String column = columnNames[i];
      if (AttachmentProviderColumns._ID.equals(column)) {
        values[i] = id;
      } else if (AttachmentProviderColumns.DATA.equals(column)) {
        values[i] = uri.toString();
      } else if (AttachmentProviderColumns.DISPLAY_NAME.equals(column)) {
        values[i] = attachmentInfo.name;
      } else if (AttachmentProviderColumns.SIZE.equals(column)) {
        values[i] = attachmentInfo.size;
      }
    }
    ret.addRow(values);
    return ret;
  }
예제 #6
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    String folderName = (String) getIntent().getSerializableExtra(EXTRA_FOLDER_NAME);
    String accountUuid = getIntent().getStringExtra(EXTRA_ACCOUNT);
    Account mAccount = Preferences.getPreferences(this).getAccount(accountUuid);

    try {
      LocalStore localStore = mAccount.getLocalStore();
      mFolder = localStore.getFolder(folderName);
      mFolder.open(OpenMode.READ_WRITE);
    } catch (MessagingException me) {
      Log.e(K9.LOG_TAG, "Unable to edit folder " + folderName + " preferences", me);
      return;
    }

    boolean isPushCapable = false;
    Store store = null;
    try {
      store = mAccount.getRemoteStore();
      isPushCapable = store.isPushCapable();
    } catch (Exception e) {
      Log.e(K9.LOG_TAG, "Could not get remote store", e);
    }

    addPreferencesFromResource(R.xml.folder_settings_preferences);

    Preference category = findPreference(PREFERENCE_TOP_CATERGORY);
    category.setTitle(folderName);

    mInTopGroup = (CheckBoxPreference) findPreference(PREFERENCE_IN_TOP_GROUP);
    mInTopGroup.setChecked(mFolder.isInTopGroup());
    mIntegrate = (CheckBoxPreference) findPreference(PREFERENCE_INTEGRATE);
    mIntegrate.setChecked(mFolder.isIntegrate());

    mDisplayClass = (ListPreference) findPreference(PREFERENCE_DISPLAY_CLASS);
    mDisplayClass.setValue(mFolder.getDisplayClass().name());
    mDisplayClass.setSummary(mDisplayClass.getEntry());
    mDisplayClass.setOnPreferenceChangeListener(
        new Preference.OnPreferenceChangeListener() {
          public boolean onPreferenceChange(Preference preference, Object newValue) {
            final String summary = newValue.toString();
            int index = mDisplayClass.findIndexOfValue(summary);
            mDisplayClass.setSummary(mDisplayClass.getEntries()[index]);
            mDisplayClass.setValue(summary);
            return false;
          }
        });

    mSyncClass = (ListPreference) findPreference(PREFERENCE_SYNC_CLASS);
    mSyncClass.setValue(mFolder.getRawSyncClass().name());
    mSyncClass.setSummary(mSyncClass.getEntry());
    mSyncClass.setOnPreferenceChangeListener(
        new Preference.OnPreferenceChangeListener() {
          public boolean onPreferenceChange(Preference preference, Object newValue) {
            final String summary = newValue.toString();
            int index = mSyncClass.findIndexOfValue(summary);
            mSyncClass.setSummary(mSyncClass.getEntries()[index]);
            mSyncClass.setValue(summary);
            return false;
          }
        });

    mPushClass = (ListPreference) findPreference(PREFERENCE_PUSH_CLASS);
    mPushClass.setEnabled(isPushCapable);
    mPushClass.setValue(mFolder.getRawPushClass().name());
    mPushClass.setSummary(mPushClass.getEntry());
    mPushClass.setOnPreferenceChangeListener(
        new Preference.OnPreferenceChangeListener() {
          public boolean onPreferenceChange(Preference preference, Object newValue) {
            final String summary = newValue.toString();
            int index = mPushClass.findIndexOfValue(summary);
            mPushClass.setSummary(mPushClass.getEntries()[index]);
            mPushClass.setValue(summary);
            return false;
          }
        });
  }