/**
  * Removes any content transfer encoding from the stream and returns a Body. This code is
  * taken/condensed from MimeUtility.decodeBody
  */
 private Body decodeBody(
     InputStream in, String contentTransferEncoding, int size, MessageRetrievalListener listener)
     throws IOException {
   // Get a properly wrapped input stream
   in = MimeUtility.getInputStreamForContentTransferEncoding(in, contentTransferEncoding);
   BinaryTempFileBody tempBody = new BinaryTempFileBody();
   OutputStream out = tempBody.getOutputStream();
   try {
     byte[] buffer = new byte[COPY_BUFFER_SIZE];
     int n = 0;
     int count = 0;
     while (-1 != (n = in.read(buffer))) {
       out.write(buffer, 0, n);
       count += n;
       /*                if (listener != null) {
           listener.loadAttachmentProgress(count * 100 / size);
       }*/
     }
   } catch (Base64DataException bde) {
     String warning = "\n\n" + Email.getMessageDecodeErrorString();
     out.write(warning.getBytes());
   } finally {
     out.close();
   }
   return tempBody;
 }
Example #2
0
  @Override
  public void onCreate(Bundle icicle) {
    super.onCreate(icicle);

    // Reset the "accounts changed" notification, now that we're here
    Email.setNotifyUiAccountsChanged(false);

    // Quickly check for bulk upgrades (from older app versions) and switch to the
    // upgrade activity if necessary
    if (UpgradeAccounts.doBulkUpgradeIfNecessary(this)) {
      finish();
      return;
    }

    // Restore accounts, if it has not happened already
    // NOTE:  This is blocking, which it should not be (in the UI thread)
    // We're going to live with this for the short term and replace with something
    // smarter.  Long-term fix:  Move this, and most of the code below, to an AsyncTask
    // and do the DB work in a thread.  Then post handler to finish() as appropriate.
    AccountBackupRestore.restoreAccountsIfNeeded(this);

    // Because the app could be reloaded (for debugging, etc.), we need to make sure that
    // SyncManager gets a chance to start.  There is no harm to starting it if it has already
    // been started
    // TODO More completely separate SyncManager from Email app
    ExchangeUtils.startExchangeService(this);

    // Find out how many accounts we have, and if there's just one, go directly to it
    Cursor c = null;
    try {
      c =
          getContentResolver()
              .query(
                  EmailContent.Account.CONTENT_URI,
                  EmailContent.Account.ID_PROJECTION,
                  null,
                  null,
                  null);
      switch (c.getCount()) {
        case 0:
          AccountSetupBasics.actionNewAccount(this);
          break;
        case 1:
          c.moveToFirst();
          long accountId = c.getLong(EmailContent.Account.CONTENT_ID_COLUMN);
          MessageList.actionHandleAccount(this, accountId, Mailbox.TYPE_INBOX);
          break;
        default:
          AccountFolderList.actionShowAccounts(this);
          break;
      }
    } finally {
      if (c != null) {
        c.close();
      }
    }

    // In all cases, do not return to this activity
    finish();
  }
 private void onInviteLinkClicked() {
   if (!isMessageOpen()) return;
   Message message = getMessage();
   String startTime = new PackedString(message.mMeetingInfo).get(MeetingInfo.MEETING_DTSTART);
   if (startTime != null) {
     long epochTimeMillis = Utility.parseEmailDateTimeToMillis(startTime);
     mCallback.onCalendarLinkClicked(epochTimeMillis);
   } else {
     Email.log("meetingInfo without DTSTART " + message.mMeetingInfo);
   }
 }
 public OutputStream getOutputStream() throws IOException {
   mFile = File.createTempFile("body", null, Email.getTempDirectory());
   mFile.deleteOnExit();
   return new FileOutputStream(mFile);
 }