Example #1
0
  private InternetAddress createAddressFromViewpoint(
      UserViewpoint viewpoint, SpecialSender fallbackAddress) {
    PersonView fromViewedBySelf =
        personViewer.getPersonView(viewpoint, viewpoint.getViewer(), PersonViewExtra.PRIMARY_EMAIL);

    InternetAddress internetAddress;

    try {
      if ((fromViewedBySelf.getEmail() != null)
          && (fromViewedBySelf.getEmail().getEmail() != null)) {
        String niceName = fromViewedBySelf.getName();
        String address = fromViewedBySelf.getEmail().getEmail();
        internetAddress = new InternetAddress(address, niceName);
      } else {
        // theoretically, we might have users in the system who do not have an e-mail, but
        // have an AIM, when we allow such users in practice, we can change this to possibly
        // use users's @aol.com address, though it's quite possible that the person does not
        // really use this address
        internetAddress = new InternetAddress(fallbackAddress.toString());
      }
    } catch (AddressException e) {
      throw new RuntimeException(e);
    } catch (UnsupportedEncodingException e) {
      throw new RuntimeException(e);
    }

    return internetAddress;
  }