public void testTextPlusRfc822Message() throws MessagingException {
    K9Activity.setLanguage(getContext(), "en");
    Locale.setDefault(Locale.US);
    TimeZone.setDefault(TimeZone.getTimeZone("GMT+01:00"));

    String bodyText = "Some text here";
    String innerBodyText = "Hey there. I'm inside a message/rfc822 (inline) attachment.";

    // Create text/plain body
    TextBody textBody = new TextBody(bodyText);

    // Create inner text/plain body
    TextBody innerBody = new TextBody(innerBodyText);

    // Create message/rfc822 body
    MimeMessage innerMessage = new MimeMessage();
    innerMessage.addSentDate(new Date(112, 02, 17));
    innerMessage.setRecipients(RecipientType.TO, new Address[] {new Address("*****@*****.**")});
    innerMessage.setSubject("Subject");
    innerMessage.setFrom(new Address("*****@*****.**"));
    innerMessage.setBody(innerBody);

    // Create multipart/mixed part
    MimeMultipart multipart = new MimeMultipart();
    MimeBodyPart bodyPart1 = new MimeBodyPart(textBody, "text/plain");
    MimeBodyPart bodyPart2 = new MimeBodyPart(innerMessage, "message/rfc822");
    bodyPart2.setHeader("Content-Disposition", "inline; filename=\"message.eml\"");
    multipart.addBodyPart(bodyPart1);
    multipart.addBodyPart(bodyPart2);

    // Create message
    MimeMessage message = new MimeMessage();
    message.setBody(multipart);

    // Extract text
    ViewableContainer container = MimeUtility.extractTextAndAttachments(getContext(), message);

    String expectedText =
        bodyText
            + "\n\n"
            + "----- message.eml ------------------------------------------------------"
            + "\n\n"
            + "From: [email protected]"
            + "\n"
            + "To: [email protected]"
            + "\n"
            + "Sent: Sat Mar 17 00:00:00 GMT+01:00 2012"
            + "\n"
            + "Subject: Subject"
            + "\n"
            + "\n"
            + innerBodyText;
    String expectedHtml =
        "<html><head/><body>"
            + "<pre style=\"white-space: pre-wrap; word-wrap:break-word; "
            + "font-family: sans-serif; margin-top: 0px\">"
            + bodyText
            + "</pre>"
            + "<p style=\"margin-top: 2.5em; margin-bottom: 1em; border-bottom: "
            + "1px solid #000\">message.eml</p>"
            + "<table style=\"border: 0\">"
            + "<tr>"
            + "<th style=\"text-align: left; vertical-align: top;\">From:</th>"
            + "<td>[email protected]</td>"
            + "</tr><tr>"
            + "<th style=\"text-align: left; vertical-align: top;\">To:</th>"
            + "<td>[email protected]</td>"
            + "</tr><tr>"
            + "<th style=\"text-align: left; vertical-align: top;\">Sent:</th>"
            + "<td>Sat Mar 17 00:00:00 GMT+01:00 2012</td>"
            + "</tr><tr>"
            + "<th style=\"text-align: left; vertical-align: top;\">Subject:</th>"
            + "<td>Subject</td>"
            + "</tr>"
            + "</table>"
            + "<pre style=\"white-space: pre-wrap; word-wrap:break-word; "
            + "font-family: sans-serif; margin-top: 0px\">"
            + innerBodyText
            + "</pre>"
            + "</body></html>";

    assertEquals(expectedText, container.text);
    assertEquals(expectedHtml, container.html);
  }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.account_setup_check_settings);
    mMessageView = (TextView) findViewById(R.id.message);
    mProgressBar = (ProgressBar) findViewById(R.id.progress);
    ((Button) findViewById(R.id.cancel)).setOnClickListener(this);

    setMessage(R.string.account_setup_check_settings_retr_info_msg);
    mProgressBar.setIndeterminate(true);

    String accountUuid = getIntent().getStringExtra(EXTRA_ACCOUNT);
    mAccount = Preferences.getPreferences(this).getAccount(accountUuid);
    mCheckIncoming = getIntent().getBooleanExtra(EXTRA_CHECK_INCOMING, false);
    mCheckOutgoing = getIntent().getBooleanExtra(EXTRA_CHECK_OUTGOING, false);

    new Thread() {
      @Override
      public void run() {
        Store store = null;
        Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
        try {
          if (mDestroyed) {
            return;
          }
          if (mCanceled) {
            finish();
            return;
          }
          if (mCheckIncoming) {
            store = mAccount.getRemoteStore();

            if (store instanceof WebDavStore) {
              setMessage(R.string.account_setup_check_settings_authenticate);
            } else {
              setMessage(R.string.account_setup_check_settings_check_incoming_msg);
            }
            store.checkSettings();

            if (store instanceof WebDavStore) {
              setMessage(R.string.account_setup_check_settings_fetch);
            }
            MessagingController.getInstance(getApplication())
                .listFoldersSynchronous(mAccount, true, null);
            MessagingController.getInstance(getApplication())
                .synchronizeMailbox(mAccount, mAccount.getInboxFolderName(), null, null);
          }
          if (mDestroyed) {
            return;
          }
          if (mCanceled) {
            finish();
            return;
          }
          if (mCheckOutgoing) {
            if (!(mAccount.getRemoteStore() instanceof WebDavStore)) {
              setMessage(R.string.account_setup_check_settings_check_outgoing_msg);
            }
            Transport transport = Transport.getInstance(mAccount);
            transport.close();
            transport.open();
            transport.close();
          }
          if (mDestroyed) {
            return;
          }
          if (mCanceled) {
            finish();
            return;
          }
          setResult(RESULT_OK);
          finish();
        } catch (final AuthenticationFailedException afe) {
          Log.e(K9.LOG_TAG, "Error while testing settings", afe);
          showErrorDialog(
              R.string.account_setup_failed_dlg_auth_message_fmt,
              afe.getMessage() == null ? "" : afe.getMessage());
        } catch (final CertificateValidationException cve) {
          Log.e(K9.LOG_TAG, "Error while testing settings", cve);
          acceptKeyDialog(R.string.account_setup_failed_dlg_certificate_message_fmt, cve);
        } catch (final Throwable t) {
          Log.e(K9.LOG_TAG, "Error while testing settings", t);
          showErrorDialog(
              R.string.account_setup_failed_dlg_server_message_fmt,
              (t.getMessage() == null ? "" : t.getMessage()));
        }
      }
    }.start();
  }
Ejemplo n.º 3
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.account_setup_options);

    mCheckFrequencyView = (Spinner) findViewById(R.id.account_check_frequency);
    mDisplayCountView = (Spinner) findViewById(R.id.account_display_count);
    mNotifyView = (CheckBox) findViewById(R.id.account_notify);
    mNotifySyncView = (CheckBox) findViewById(R.id.account_notify_sync);
    mPushEnable = (CheckBox) findViewById(R.id.account_enable_push);

    findViewById(R.id.next).setOnClickListener(this);

    SpinnerOption checkFrequencies[] = {
      new SpinnerOption(-1, getString(R.string.account_setup_options_mail_check_frequency_never)),
      new SpinnerOption(1, getString(R.string.account_setup_options_mail_check_frequency_1min)),
      new SpinnerOption(5, getString(R.string.account_setup_options_mail_check_frequency_5min)),
      new SpinnerOption(10, getString(R.string.account_setup_options_mail_check_frequency_10min)),
      new SpinnerOption(15, getString(R.string.account_setup_options_mail_check_frequency_15min)),
      new SpinnerOption(30, getString(R.string.account_setup_options_mail_check_frequency_30min)),
      new SpinnerOption(60, getString(R.string.account_setup_options_mail_check_frequency_1hour)),
      new SpinnerOption(120, getString(R.string.account_setup_options_mail_check_frequency_2hour)),
      new SpinnerOption(180, getString(R.string.account_setup_options_mail_check_frequency_3hour)),
      new SpinnerOption(360, getString(R.string.account_setup_options_mail_check_frequency_6hour)),
      new SpinnerOption(720, getString(R.string.account_setup_options_mail_check_frequency_12hour)),
      new SpinnerOption(
          1440, getString(R.string.account_setup_options_mail_check_frequency_24hour)),
    };

    ArrayAdapter<SpinnerOption> checkFrequenciesAdapter =
        new ArrayAdapter<SpinnerOption>(
            this, android.R.layout.simple_spinner_item, checkFrequencies);
    checkFrequenciesAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    mCheckFrequencyView.setAdapter(checkFrequenciesAdapter);

    SpinnerOption displayCounts[] = {
      new SpinnerOption(10, getString(R.string.account_setup_options_mail_display_count_10)),
      new SpinnerOption(25, getString(R.string.account_setup_options_mail_display_count_25)),
      new SpinnerOption(50, getString(R.string.account_setup_options_mail_display_count_50)),
      new SpinnerOption(100, getString(R.string.account_setup_options_mail_display_count_100)),
      new SpinnerOption(250, getString(R.string.account_setup_options_mail_display_count_250)),
      new SpinnerOption(500, getString(R.string.account_setup_options_mail_display_count_500)),
      new SpinnerOption(1000, getString(R.string.account_setup_options_mail_display_count_1000)),
    };

    ArrayAdapter<SpinnerOption> displayCountsAdapter =
        new ArrayAdapter<SpinnerOption>(this, android.R.layout.simple_spinner_item, displayCounts);
    displayCountsAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    mDisplayCountView.setAdapter(displayCountsAdapter);

    String accountUuid = getIntent().getStringExtra(EXTRA_ACCOUNT);
    mAccount = Preferences.getPreferences(this).getAccount(accountUuid);

    mNotifyView.setChecked(mAccount.isNotifyNewMail());
    mNotifySyncView.setChecked(mAccount.isShowOngoing());
    SpinnerOption.setSpinnerOptionValue(
        mCheckFrequencyView, mAccount.getAutomaticCheckIntervalMinutes());
    SpinnerOption.setSpinnerOptionValue(mDisplayCountView, mAccount.getDisplayCount());

    boolean isPushCapable = false;
    try {
      Store store = mAccount.getRemoteStore();
      isPushCapable = store.isPushCapable();
    } catch (Exception e) {
      Log.e(K9.LOG_TAG, "Could not get remote store", e);
    }

    if (!isPushCapable) {
      mPushEnable.setVisibility(View.GONE);
    } else {
      mPushEnable.setChecked(true);
    }
  }
 @Override
 public void onDestroy() {
   super.onDestroy();
   mDestroyed = true;
   mCanceled = true;
 }