⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jwmacontroller.java

📁 java windows mda and reveus
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
      //3. stream out part      ServletOutputStream out =          session.getResponse().getOutputStream();      folder.writeMessagePart(part.getPart(), out);    } catch (Exception ex) {      throw new JwmaException("message.displaypart.failed").setException(ex);    }  }//doDisplayMessagePart  /*** End Message Actions ************************************************/  /*** Preferences Actions ************************************************/  /**   * Updates the preferences for system settings.   * <p>   * This method handles first-time login too,   * just allowing to set firstname and lastname.   *   * @param session a <tt>JwmaSession</tt> instance.   *   * @throws JwmaException if it fails to execute properly.   */  private void doUpdatePreferences(JwmaSession session)      throws JwmaException {    JwmaPreferencesImpl prefs = session.getPreferences();    JwmaStoreImpl store = session.getJwmaStore();    //if anything is set then to the default    JwmaMailIdentityImpl mailid = null;    //collect data    String firstname = session.getRequestParameter("firstname");    String lastname = session.getRequestParameter("lastname");    String quotechar = session.getRequestParameter("quotechar");    String rootfolder = session.getRequestParameter("rootfolder");    String trashfolder = session.getRequestParameter("trashfolder");    String draftfolder = session.getRequestParameter("draftfolder");    String sentmailarchive = session.getRequestParameter("sentmailarchive");    String readmailarchive = session.getRequestParameter("readmailarchive");    String language = session.getRequestParameter("language");    String msgprocessor = session.getRequestParameter("msgprocessor");    String dfpattern = session.getRequestParameter("dfpattern");    String style = session.getRequestParameter("style");    boolean autoquote = new Boolean(        session.getRequestParameter("autoquote")).booleanValue();    boolean autoempty = new Boolean(        session.getRequestParameter("autoempty")).booleanValue();    boolean automoveread = new Boolean(        session.getRequestParameter("automoveread")).booleanValue();    boolean autoarchivesent = new Boolean(        session.getRequestParameter("autoarchivesent")).booleanValue();    boolean expert = new Boolean(        session.getRequestParameter("expert")).booleanValue();    boolean inlined = new Boolean(        session.getRequestParameter("inlined")).booleanValue();    prefs.setAutoQuote(autoquote);    prefs.setAutoEmpty(autoempty);    prefs.setAutoMoveRead(automoveread);    prefs.setAutoArchiveSent(autoarchivesent);    prefs.setDisplayingInlined(inlined);    //if not expert, try to update the default mail identity    if (!expert && !prefs.isExpert()) {      //log.debug("updatePreferences():updating mail identity");      updateMailIdentity(          session,          (JwmaMailIdentityImpl) prefs.getMailIdentity()      );    }    prefs.setExpert(expert);    if (firstname != null) {      prefs.setFirstname(firstname);    }    if (lastname != null) {      prefs.setLastname(lastname);    }    if (quotechar != null) {      prefs.setQuoteChar(quotechar);    }    //update send-mail archive    if (autoarchivesent) {      if(!prefs.isExpert()) {        //set the new folder, will set the prefs        store.setSentMailFolder(prefs.getSentMailArchive());      } else {        //set the new folder, will set the prefs        store.setSentMailFolder(sentmailarchive);      }    }    if (automoveread) {      if(!prefs.isExpert()) {        //set the new folder, will set the prefs        store.setReadMailFolder(prefs.getReadMailArchive());      } else {        //set the new folder, will set the prefs        store.setReadMailFolder(readmailarchive);      }    }    if(trashfolder != null) {      store.setTrashFolder(trashfolder);    }    if(draftfolder != null) {      store.setDraftFolder(draftfolder);    }    if(rootfolder != null) {      store.updateRootFolder(rootfolder);    }    if (msgprocessor != null) {      prefs.setMessageProcessorName(msgprocessor);    }    if (dfpattern != null) {      prefs.setDateFormat(new SimpleDateFormat(dfpattern));    }    if (language != null) {      //create locale      Locale locale = new Locale(language, "");      //set the locale if it is supported and not the one that      //is already set      if (JwmaKernel.getReference().getConfiguration()              .getI18N().isSupportedViewLocale(locale)          && !locale.equals(prefs.getLocale())) {        prefs.setLocale(locale);        session.setLocale();      }    }    if (style !=null) {      prefs.setStyle(style);    }    //save    session.savePreferences();    session.redirect(JwmaKernel.PREFERENCES_VIEW);  }//doUpdatePreferences  /**   * Adds a mail identity.   *   * @param session a <tt>JwmaSession</tt> instance.   *   * @throws JwmaException if it fails to execute properly.   */  private void doAddMailIdentity(JwmaSession session)      throws JwmaException {    JwmaPreferencesImpl prefs = session.getPreferences();    JwmaMailIdentityImpl mid = prefs.createMailIdentity();    RandomAppendPlugin rap = JwmaKernel.getReference().getRandomAppendPlugin();    //retrieve parameters    String name = session.getRequestParameter("mid.name");    String from = session.getRequestParameter("mid.from");    boolean defaultmid = new Boolean(        session.getRequestParameter("mid.default")).booleanValue();    if (name != null && name.length() > 0) {      mid.setName(name);    } else {      throw new JwmaException("preferences.mailid.noname");    }    if (from != null) {      try {        InternetAddress.parse(from);      } catch (AddressException adrex) {        throw new JwmaException("preferences.update.addressinvalid", true);      }      mid.setFrom(from);    }    //add the new instance    prefs.addMailIdentity(mid);    //and set it as default if requested    if (defaultmid) {      prefs.setDefaultMailIdentity(mid.getUID());    }    //save    session.savePreferences();    //redirect    session.redirect(JwmaKernel.PREFERENCES_VIEW);  }//doAddMailIdentity  /**   * Removes a mail identity.   *   * @param session a <tt>JwmaSession</tt> instance.   *   * @throws JwmaException if it fails to execute properly.   */  private void doRemoveMailIdentity(JwmaSession session, String uid)      throws JwmaException {    JwmaPreferencesImpl prefs = session.getPreferences();    if (prefs.existsMailIdentity(uid)) {      //remove the instance      prefs.removeMailIdentity(uid);    } else {      throw new JwmaException("preferences.mailid.invaliduid");    }    //save    session.savePreferences();    //redirect    session.redirect(JwmaKernel.PREFERENCES_VIEW);  }//doRemoveMailIdentity  /**   * Updates a mail identity.   *   * @param session a <tt>JwmaSession</tt> instance.   *   * @throws JwmaException if it fails to execute properly.   */  private void doUpdateMailIdentity(JwmaSession session, String uid)      throws JwmaException {    JwmaPreferencesImpl prefs = session.getPreferences();    if (prefs.existsMailIdentity(uid)) {      //make the update      updateMailIdentity(          session,          (JwmaMailIdentityImpl) prefs.getMailIdentity(uid)      );    } else {      throw new JwmaException("preferences.mailid.invaliduid");    }    //save    session.savePreferences();    //redirect    session.redirect(JwmaKernel.PREFERENCES_VIEW);  }//doUpdateMailIdentity  private void updateMailIdentity(JwmaSession session, JwmaMailIdentityImpl mid)      throws JwmaException {    RandomAppendPlugin rap = JwmaKernel.getReference().getRandomAppendPlugin();    JwmaPreferencesImpl prefs = session.getPreferences();    //collect data    String name = session.getRequestParameter("mid.name");    String from = session.getRequestParameter("mid.from");    String replyto = session.getRequestParameter("mid.replyto");    String signature = session.getRequestParameter("mid.signature");    String note = session.getRequestParameter("mid.note");    String rndappendtype = session.getRequestParameter("mid.rndappendtype");    String relcontact = session.getRequestParameter("mid.relcontact");    boolean defaultmid = new Boolean(        session.getRequestParameter("mid.default")).booleanValue();    boolean autosigning = new Boolean(        session.getRequestParameter("mid.autosigning")).booleanValue();    if (name != null) {      mid.setName(name);    }    if (from != null) {      try {        InternetAddress.parse(from);      } catch (AddressException adrex) {        throw new JwmaException("preferences.update.addressinvalid", true);      }      mid.setFrom(from);    }    if (replyto != null) {      try {        InternetAddress.parse(replyto);      } catch (AddressException adrex) {        throw new JwmaException("preferences.update.addressinvalid", true);      }      mid.setReplyTo(replyto);    }    if (signature != null) {      mid.setSignature(signature);    } else {      mid.setSignature("");    }    if (note != null) {      mid.setNote(note);    } else {      mid.setNote("");    }    if (rndappendtype != null && rap != null        && rap.supportsAppendType(rndappendtype,            prefs.getLocale())) {      mid.setRandomAppendType(rndappendtype, prefs.getLocale());    }    if (relcontact != null) {      mid.setRelatedContact(relcontact);    } else {      mid.setRelatedContact("");    }    mid.setAutoSigning(autosigning);    if (defaultmid) {      prefs.setDefaultMailIdentity(mid.getUID());    }  }//updateMailIdenitity  /*** End Preferences Actions *******************************************/  /*** Helper methods ****************************************************/  /**   * Converts a <tt>String</tt> into an <tt>int</tt>.   */  private int toInt(String number) throws JwmaException {    try {      return Integer.parseInt(number);    } catch (Exception ex) {      throw new JwmaException("jwma.number.format");    }  }//toInt  /**   * Converts a <tt>String[]</tt> into an <tt>int[]</tt>.   * Performs a trim on each string.   */  private int[] toInts(String[] numbers) throws JwmaException {    int[] msgnum = new int[numbers.length];    for (int i = 0; i < numbers.length; i++) {      msgnum[i] = toInt(numbers[i].trim());    }    return msgnum;  }//toInts  /*** End Helper methods ************************************************/  /**   * Returns servlet info as <tt>String</tt>.   *   * @return Info about this servlet as <tt>String</tt>.   */  public String getServletInfo() {    return "jwma (Java WebMail) Controller Servlet";  }//getServletInfo()  private static final int COOKIE_EXPIRES = (60 * 24 * 60 * 60); // d -> h -> min -> s}//class JwmaController

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -