Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 89239e80 authored by Ashwini Munigala's avatar Ashwini Munigala Committed by Linux Build Service Account
Browse files

MAP: Modify fetch MessageSize email to get emailBody storage file size

Email App Implementation moved email body parts storage to files
instead of direct db entries. Modify MessageSize email to fetch
contentURI and calculate size of corresponding files from Email db.

Change-Id: I6176485e4c2fe95b8310fd8316d8b14f347f88e1
CRs-fixed: 731435
parent d4d4b642
Loading
Loading
Loading
Loading
+73 −42
Original line number Diff line number Diff line
@@ -667,23 +667,49 @@ public class BluetoothMapContent {
                size = subject.length();
            } else if (fi.msgType == FilterInfo.TYPE_MMS) {
                size = c.getInt(c.getColumnIndex(Mms.MESSAGE_SIZE));
            } else {
            } else  if (fi.msgType == FilterInfo.TYPE_EMAIL) {
                long msgId = Long.valueOf(c.getString(c.getColumnIndex("_id")));
                String[] EMAIL_MSGSIZE_PROJECTION = new String[] { "LENGTH(textContent)", "LENGTH(htmlContent)" };
                String textContent, htmlContent;
                Uri uri = Uri.parse("content://com.android.email.provider/body");
                String where = setWhereFilterMessagekey(msgId);
                Cursor cr = mResolver.query(
                    uri, EMAIL_MSGSIZE_PROJECTION, where , null, null);
                Uri uriAddress = Uri.parse("content://com.android.email.provider/body");
                Cursor cr = mResolver.query(uriAddress,
                    Body.CONTENT_PROJECTION, BodyColumns.MESSAGE_KEY + "=?",
                    new String[] {String.valueOf(msgId)}, null);
                if (cr != null && cr.moveToFirst()) {
                    do {
                       size = cr.getInt(0);
                       if(size == -1 || size == 0)
                          size = cr.getInt(1);
                          break;
                    } while (cr.moveToNext());
                    ParcelFileDescriptor fd = null;
                    String textContentURI = cr.getString(cr.getColumnIndex(
                                                BodyColumns.TEXT_CONTENT_URI));
                    if (textContentURI != null ) {
                        try {
                           Log.v(TAG, " TRY EMAIL BODY textURI " + textContentURI);
                           fd = mResolver.openFileDescriptor(Uri.parse(textContentURI), "r");
                        } catch (FileNotFoundException ex) {
                           if(V) Log.w(TAG, ex);
                        }
                    }
                    if(fd == null ) {
                       String htmlContentURI = cr.getString(cr.getColumnIndex(
                                                   BodyColumns.HTML_CONTENT_URI));
                       if (htmlContentURI != null ) {
                           try {
                             Log.v(TAG, " TRY EMAIL BODY htmlURI " + htmlContentURI);
                             fd = mResolver.openFileDescriptor(Uri.parse(htmlContentURI), "r");
                           } catch (FileNotFoundException ex) {
                               if(V) Log.w(TAG, ex);
                           }
                       }
                   }
                   if(fd != null ) {
                       //Size in bytes
                       size = (Long.valueOf(fd.getStatSize()).intValue());
                       try {
                           fd.close();
                       } catch (IOException ex) {
                           if(V) Log.w(TAG, ex);
                       }

                   } else {
                        Log.e(TAG, "MessageSize Email NOT AVAILABLE");
                   }
                if (cr != null) {
                   cr.close();
                }
            }
@@ -1996,7 +2022,6 @@ public class BluetoothMapContent {
    private void extractEmailParts(long id, BluetoothMapbMessageMmsEmail message)
    {
        if (V) Log.v(TAG, "extractEmailParts with id " + id);
        String where = setWhereFilterMessagekey(id);
        String emailBody = "";
        Uri uriAddress = Uri.parse("content://com.android.email.provider/body");
        BluetoothMapbMessageMmsEmail.MimePart part;
@@ -2021,21 +2046,24 @@ public class BluetoothMapContent {
                    }
                    // GET FD to parse text or HTML content
                    ParcelFileDescriptor fd = null;
                    if(textContentURI != null ) {
                        try {
                           Log.v(TAG, " TRY EMAIL BODY textURI " + textContentURI);
                           fd = mResolver.openFileDescriptor(Uri.parse(textContentURI), "r");
                        } catch (FileNotFoundException e) {
                      Log.w(TAG, e);
                           if(V) Log.w(TAG, e);
                        }
                    }
                    if(fd == null ) {
                        if(htmlContentURI != null ) {
                            //Try HTML content if  TEXT CONTENT NULL
                            try {
                                Log.v(TAG, " TRY EMAIL BODY htmlURI " + htmlContentURI);
                                fd = mResolver.openFileDescriptor(Uri.parse(htmlContentURI), "r");
                                } catch (FileNotFoundException e) {
                           Log.w(TAG, e);
                                if(V) Log.w(TAG, e);
                            } catch (NullPointerException e) {
                          Log.w(TAG, e);
                                if(V) Log.w(TAG, e);
                            }
                            String msgBody = readEmailBodyForMessageFd(fd);
                            if (msgBody != null) {
@@ -2049,6 +2077,9 @@ public class BluetoothMapContent {
                                emailBody = emailBody.replaceAll("(?s)(\\r)", "");
                                emailBody = emailBody.replaceAll("(?s)(\\n)", "\r\n");
                            }
                        } else {
                           Log.w(TAG, " FETCH Email BODY File HTML URI FAILED");
                        }
                    } else {
                        emailBody = readEmailBodyForMessageFd(fd);
                    }