Example #1
0
  @Test
  public void migrateHtmlWithRelatedMessage() throws Exception {
    SQLiteDatabase db = createV50Database();
    insertHtmlWithRelatedMessage(db);
    db.close();

    LocalStore localStore = LocalStore.getInstance(account, RuntimeEnvironment.application);

    LocalMessage msg = localStore.getFolder("dev").getMessage("10");
    FetchProfile fp = new FetchProfile();
    fp.add(FetchProfile.Item.BODY);
    localStore.getFolder("dev").fetch(Collections.singletonList(msg), fp, null);

    Assert.assertEquals(9, msg.getId());
    Assert.assertEquals(11, msg.getHeaderNames().size());
    Assert.assertEquals("multipart/mixed", msg.getMimeType());
    Assert.assertEquals(1, msg.getAttachmentCount());

    Multipart msgBody = (Multipart) msg.getBody();
    Assert.assertEquals("------------050707070308090509030605", msgBody.getBoundary());

    Multipart multipartAlternativePart = (Multipart) msgBody.getBodyPart(0).getBody();
    BodyPart htmlPart = multipartAlternativePart.getBodyPart(1);
    String msgTextContent = MessageExtractor.getTextFromPart(htmlPart);
    Assert.assertNotNull(msgTextContent);
    Assert.assertTrue(msgTextContent.contains("cid:[email protected]"));

    Assert.assertEquals("image/jpeg", msgBody.getBodyPart(1).getMimeType());
  }
Example #2
0
  @Test
  public void migratePgpMimeSignedMessage() throws Exception {
    SQLiteDatabase db = createV50Database();
    insertPgpMimeSignedMessage(db);
    db.close();

    LocalStore localStore = LocalStore.getInstance(account, RuntimeEnvironment.application);

    LocalMessage msg = localStore.getFolder("dev").getMessage("5");
    FetchProfile fp = new FetchProfile();
    fp.add(FetchProfile.Item.BODY);
    localStore.getFolder("dev").fetch(Collections.singletonList(msg), fp, null);

    Assert.assertEquals(4, msg.getId());
    Assert.assertEquals(8, msg.getHeaderNames().size());
    Assert.assertEquals("multipart/mixed", msg.getMimeType());
    Assert.assertEquals(2, msg.getAttachmentCount());

    Multipart body = (Multipart) msg.getBody();
    Assert.assertEquals(3, body.getCount());

    Assert.assertEquals("multipart/alternative", body.getBodyPart(0).getMimeType());
    Assert.assertEquals("image/png", body.getBodyPart(1).getMimeType());
    Assert.assertEquals("application/pgp-signature", body.getBodyPart(2).getMimeType());
  }
Example #3
0
  @Test
  public void migratePgpMimeEncryptedMessage() throws Exception {
    SQLiteDatabase db = createV50Database();
    insertPgpMimeEncryptedMessage(db);
    db.close();

    LocalStore localStore = LocalStore.getInstance(account, RuntimeEnvironment.application);

    LocalMessage msg = localStore.getFolder("dev").getMessage("6");
    FetchProfile fp = new FetchProfile();
    fp.add(FetchProfile.Item.BODY);
    localStore.getFolder("dev").fetch(Collections.singletonList(msg), fp, null);

    Assert.assertEquals(5, msg.getId());
    Assert.assertEquals(13, msg.getHeaderNames().size());
    Assert.assertEquals("multipart/encrypted", msg.getMimeType());
    Assert.assertEquals(2, msg.getAttachmentCount());

    Multipart body = (Multipart) msg.getBody();
    Assert.assertEquals(1, msg.getHeader(MimeHeader.HEADER_CONTENT_TYPE).length);
    Assert.assertEquals(
        "application/pgp-encrypted",
        MimeUtility.getHeaderParameter(
            msg.getHeader(MimeHeader.HEADER_CONTENT_TYPE)[0], "protocol"));
    Assert.assertEquals(
        "UoPmpPX/dBe4BELn",
        MimeUtility.getHeaderParameter(
            msg.getHeader(MimeHeader.HEADER_CONTENT_TYPE)[0], "boundary"));
    Assert.assertEquals("UoPmpPX/dBe4BELn", body.getBoundary());
    Assert.assertEquals(2, body.getCount());

    Assert.assertEquals("application/pgp-encrypted", body.getBodyPart(0).getMimeType());
    Assert.assertEquals("application/octet-stream", body.getBodyPart(1).getMimeType());
  }
Example #4
0
  @Test
  public void migrateTextPlain() throws Exception {
    SQLiteDatabase db = createV50Database();
    insertSimplePlaintextMessage(db);
    db.close();

    LocalStore localStore = LocalStore.getInstance(account, RuntimeEnvironment.application);

    LocalMessage msg = localStore.getFolder("dev").getMessage("3");
    FetchProfile fp = new FetchProfile();
    fp.add(FetchProfile.Item.BODY);
    localStore.getFolder("dev").fetch(Collections.singletonList(msg), fp, null);

    Assert.assertEquals("text/plain", msg.getMimeType());
    Assert.assertEquals(2, msg.getId());
    Assert.assertEquals(13, msg.getHeaderNames().size());
    Assert.assertEquals(0, msg.getAttachmentCount());

    Assert.assertEquals(1, msg.getHeader("User-Agent").length);
    Assert.assertEquals("Mutt/1.5.24 (2015-08-30)", msg.getHeader("User-Agent")[0]);
    Assert.assertEquals(1, msg.getHeader(MimeHeader.HEADER_CONTENT_TYPE).length);
    Assert.assertEquals(
        "text/plain",
        MimeUtility.getHeaderParameter(msg.getHeader(MimeHeader.HEADER_CONTENT_TYPE)[0], null));
    Assert.assertEquals(
        "utf-8",
        MimeUtility.getHeaderParameter(
            msg.getHeader(MimeHeader.HEADER_CONTENT_TYPE)[0], "charset"));

    Assert.assertTrue(msg.getBody() instanceof BinaryMemoryBody);

    String msgTextContent = MessageExtractor.getTextFromPart(msg);
    Assert.assertEquals("nothing special here.\r\n", msgTextContent);
  }
Example #5
0
  @Test
  public void migrateMixedWithAttachments() throws Exception {
    SQLiteDatabase db = createV50Database();
    insertMixedWithAttachments(db);
    db.close();

    LocalStore localStore = LocalStore.getInstance(account, RuntimeEnvironment.application);

    LocalMessage msg = localStore.getFolder("dev").getMessage("4");
    FetchProfile fp = new FetchProfile();
    fp.add(FetchProfile.Item.BODY);
    localStore.getFolder("dev").fetch(Collections.singletonList(msg), fp, null);

    Assert.assertEquals(3, msg.getId());
    Assert.assertEquals(8, msg.getHeaderNames().size());
    Assert.assertEquals("multipart/mixed", msg.getMimeType());
    Assert.assertEquals(1, msg.getHeader(MimeHeader.HEADER_CONTENT_TYPE).length);
    Assert.assertEquals(
        "multipart/mixed",
        MimeUtility.getHeaderParameter(msg.getHeader(MimeHeader.HEADER_CONTENT_TYPE)[0], null));
    Assert.assertEquals(
        "----5D6OUTIYLNN2X63O0R2M0V53TOUAQP",
        MimeUtility.getHeaderParameter(
            msg.getHeader(MimeHeader.HEADER_CONTENT_TYPE)[0], "boundary"));
    Assert.assertEquals(2, msg.getAttachmentCount());

    Multipart body = (Multipart) msg.getBody();
    Assert.assertEquals(3, body.getCount());

    Assert.assertEquals("multipart/alternative", body.getBodyPart(0).getMimeType());
    LocalBodyPart attachmentPart = (LocalBodyPart) body.getBodyPart(1);
    Assert.assertEquals("image/png", attachmentPart.getMimeType());
    Assert.assertEquals("2", attachmentPart.getServerExtra());
    Assert.assertEquals("k9small.png", attachmentPart.getDisplayName());
    Assert.assertEquals(
        "attachment", MimeUtility.getHeaderParameter(attachmentPart.getDisposition(), null));
    Assert.assertEquals(
        "k9small.png", MimeUtility.getHeaderParameter(attachmentPart.getDisposition(), "filename"));
    Assert.assertEquals(
        "2250", MimeUtility.getHeaderParameter(attachmentPart.getDisposition(), "size"));
    Assert.assertTrue(attachmentPart.isFirstClassAttachment());

    FileBackedBody attachmentBody = (FileBackedBody) attachmentPart.getBody();
    Assert.assertEquals(2250, attachmentBody.getSize());
    Assert.assertEquals(MimeUtil.ENC_BINARY, attachmentBody.getEncoding());

    Assert.assertEquals("application/whatevs", body.getBodyPart(2).getMimeType());
    Assert.assertNull(body.getBodyPart(2).getBody());
  }
Example #6
0
 @Override
 protected List<RemindMe> doInBackground(Void... params) {
   try {
     LocalStore store = LocalStore.getInstance(account, context);
     LocalRemindMe localRemindMe = new LocalRemindMe(store);
     return localRemindMe.getAllRemindMes();
   } catch (MessagingException e) {
     Log.e(K9.LOG_TAG, "Unable to retrieve FollowUps", e);
   }
   return null;
 }
Example #7
0
  @Test
  public void migrateTextHtml() throws Exception {
    SQLiteDatabase db = createV50Database();
    insertMultipartAlternativeMessage(db);
    db.close();

    LocalStore localStore = LocalStore.getInstance(account, RuntimeEnvironment.application);

    LocalMessage msg = localStore.getFolder("dev").getMessage("9");
    FetchProfile fp = new FetchProfile();
    fp.add(FetchProfile.Item.BODY);
    localStore.getFolder("dev").fetch(Collections.singletonList(msg), fp, null);

    Assert.assertEquals(8, msg.getId());
    Assert.assertEquals(9, msg.getHeaderNames().size());
    Assert.assertEquals("multipart/alternative", msg.getMimeType());
    Assert.assertEquals(0, msg.getAttachmentCount());

    Multipart msgBody = (Multipart) msg.getBody();
    Assert.assertEquals("------------060200010509000000040004", msgBody.getBoundary());
  }
Example #8
0
  @Test
  public void migratePgpInlineClearsignedMessage() throws Exception {
    SQLiteDatabase db = createV50Database();
    insertPgpInlineClearsignedMessage(db);
    db.close();

    LocalStore localStore = LocalStore.getInstance(account, RuntimeEnvironment.application);

    LocalMessage msg = localStore.getFolder("dev").getMessage("8");
    FetchProfile fp = new FetchProfile();
    fp.add(FetchProfile.Item.BODY);
    localStore.getFolder("dev").fetch(Collections.singletonList(msg), fp, null);

    Assert.assertEquals(7, msg.getId());
    Assert.assertEquals(12, msg.getHeaderNames().size());
    Assert.assertEquals("text/plain", msg.getMimeType());
    Assert.assertEquals(0, msg.getAttachmentCount());
    Assert.assertTrue(msg.getBody() instanceof BinaryMemoryBody);

    String msgTextContent = MessageExtractor.getTextFromPart(msg);
    Assert.assertEquals(
        OpenPgpUtils.PARSE_RESULT_SIGNED_MESSAGE, OpenPgpUtils.parseMessage(msgTextContent));
  }
Example #9
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.getInstance(account, getContext()).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;
  }
Example #10
0
  private String getType(String dbName, String id, String format, String mimeType) {
    String type;
    if (FORMAT_THUMBNAIL.equals(format)) {
      type = "image/png";
    } else {
      final Account account = Preferences.getPreferences(getContext()).getAccount(dbName);

      try {
        final LocalStore localStore = LocalStore.getInstance(account, getContext());

        AttachmentInfo attachmentInfo = localStore.getAttachmentInfo(id);
        if (FORMAT_VIEW.equals(format) && mimeType != null) {
          type = mimeType;
        } else {
          type = attachmentInfo.type;
        }
      } catch (MessagingException e) {
        Log.e(K9.LOG_TAG, "Unable to retrieve LocalStore for " + account, e);
        type = null;
      }
    }

    return type;
  }