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 Original line Diff line number Diff line
@@ -667,23 +667,49 @@ public class BluetoothMapContent {
                size = subject.length();
                size = subject.length();
            } else if (fi.msgType == FilterInfo.TYPE_MMS) {
            } else if (fi.msgType == FilterInfo.TYPE_MMS) {
                size = c.getInt(c.getColumnIndex(Mms.MESSAGE_SIZE));
                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")));
                long msgId = Long.valueOf(c.getString(c.getColumnIndex("_id")));
                String[] EMAIL_MSGSIZE_PROJECTION = new String[] { "LENGTH(textContent)", "LENGTH(htmlContent)" };
                String textContent, htmlContent;
                String textContent, htmlContent;
                Uri uri = Uri.parse("content://com.android.email.provider/body");
                Uri uriAddress = Uri.parse("content://com.android.email.provider/body");
                String where = setWhereFilterMessagekey(msgId);
                Cursor cr = mResolver.query(uriAddress,
                Cursor cr = mResolver.query(
                    Body.CONTENT_PROJECTION, BodyColumns.MESSAGE_KEY + "=?",
                    uri, EMAIL_MSGSIZE_PROJECTION, where , null, null);
                    new String[] {String.valueOf(msgId)}, null);
                if (cr != null && cr.moveToFirst()) {
                if (cr != null && cr.moveToFirst()) {
                    do {
                    ParcelFileDescriptor fd = null;
                       size = cr.getInt(0);
                    String textContentURI = cr.getString(cr.getColumnIndex(
                       if(size == -1 || size == 0)
                                                BodyColumns.TEXT_CONTENT_URI));
                          size = cr.getInt(1);
                    if (textContentURI != null ) {
                          break;
                        try {
                    } while (cr.moveToNext());
                           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();
                   cr.close();
                }
                }
            }
            }
@@ -1996,7 +2022,6 @@ public class BluetoothMapContent {
    private void extractEmailParts(long id, BluetoothMapbMessageMmsEmail message)
    private void extractEmailParts(long id, BluetoothMapbMessageMmsEmail message)
    {
    {
        if (V) Log.v(TAG, "extractEmailParts with id " + id);
        if (V) Log.v(TAG, "extractEmailParts with id " + id);
        String where = setWhereFilterMessagekey(id);
        String emailBody = "";
        String emailBody = "";
        Uri uriAddress = Uri.parse("content://com.android.email.provider/body");
        Uri uriAddress = Uri.parse("content://com.android.email.provider/body");
        BluetoothMapbMessageMmsEmail.MimePart part;
        BluetoothMapbMessageMmsEmail.MimePart part;
@@ -2021,21 +2046,24 @@ public class BluetoothMapContent {
                    }
                    }
                    // GET FD to parse text or HTML content
                    // GET FD to parse text or HTML content
                    ParcelFileDescriptor fd = null;
                    ParcelFileDescriptor fd = null;
                    if(textContentURI != null ) {
                        try {
                        try {
                           Log.v(TAG, " TRY EMAIL BODY textURI " + textContentURI);
                           Log.v(TAG, " TRY EMAIL BODY textURI " + textContentURI);
                           fd = mResolver.openFileDescriptor(Uri.parse(textContentURI), "r");
                           fd = mResolver.openFileDescriptor(Uri.parse(textContentURI), "r");
                        } catch (FileNotFoundException e) {
                        } catch (FileNotFoundException e) {
                      Log.w(TAG, e);
                           if(V) Log.w(TAG, e);
                        }
                    }
                    }
                    if(fd == null ) {
                    if(fd == null ) {
                        if(htmlContentURI != null ) {
                            //Try HTML content if  TEXT CONTENT NULL
                            //Try HTML content if  TEXT CONTENT NULL
                            try {
                            try {
                                Log.v(TAG, " TRY EMAIL BODY htmlURI " + htmlContentURI);
                                Log.v(TAG, " TRY EMAIL BODY htmlURI " + htmlContentURI);
                                fd = mResolver.openFileDescriptor(Uri.parse(htmlContentURI), "r");
                                fd = mResolver.openFileDescriptor(Uri.parse(htmlContentURI), "r");
                                } catch (FileNotFoundException e) {
                                } catch (FileNotFoundException e) {
                           Log.w(TAG, e);
                                if(V) Log.w(TAG, e);
                            } catch (NullPointerException e) {
                            } catch (NullPointerException e) {
                          Log.w(TAG, e);
                                if(V) Log.w(TAG, e);
                            }
                            }
                            String msgBody = readEmailBodyForMessageFd(fd);
                            String msgBody = readEmailBodyForMessageFd(fd);
                            if (msgBody != null) {
                            if (msgBody != null) {
@@ -2049,6 +2077,9 @@ public class BluetoothMapContent {
                                emailBody = emailBody.replaceAll("(?s)(\\r)", "");
                                emailBody = emailBody.replaceAll("(?s)(\\r)", "");
                                emailBody = emailBody.replaceAll("(?s)(\\n)", "\r\n");
                                emailBody = emailBody.replaceAll("(?s)(\\n)", "\r\n");
                            }
                            }
                        } else {
                           Log.w(TAG, " FETCH Email BODY File HTML URI FAILED");
                        }
                    } else {
                    } else {
                        emailBody = readEmailBodyForMessageFd(fd);
                        emailBody = readEmailBodyForMessageFd(fd);
                    }
                    }