コード例 #1
0
ファイル: AttachmentProvider.java プロジェクト: NioDev/k-9
  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
ファイル: MessageProvider.java プロジェクト: rbayer/k-9
  @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;
  }
コード例 #3
0
ファイル: AttachmentProvider.java プロジェクト: NioDev/k-9
  @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;
  }