001/* 002 * Copyright 2021 Anyware Services 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.ametys.plugins.calendar.icsreader.ical4j; 017 018import java.net.URI; 019import java.net.URISyntaxException; 020 021import net.fortuna.ical4j.model.Content; 022import net.fortuna.ical4j.model.Parameter; 023import net.fortuna.ical4j.model.ParameterFactory; 024import net.fortuna.ical4j.util.Strings; 025import net.fortuna.ical4j.util.Uris; 026 027/** 028 * From specification: 029 * 030 * <pre> 031 * Parameter Name: EMAIL 032 * 033 * Purpose: To specify an email address that is used to identify or 034 * contact an organizer or attendee. 035 * 036 * Format Definition: This property parameter is defined by the 037 * following notation: 038 * 039 * emailparam = "EMAIL" "=" param-value 040 * 041 * Description: This property parameter MAY be specified on "ORGANIZER" 042 * or "ATTENDEE" properties. This property can be used in situations 043 * where the calendar user address value of "ORGANIZER" and 044 * "ATTENDEE" properties is not likely to be an identifier that 045 * recipients of scheduling messages could use to match the calendar 046 * user with, for example, an address book entry. The value of this 047 * property is an email address that can easily be matched by 048 * recipients. Recipients can also use this value as an alternative 049 * means of contacting the calendar user via email. If a recipient's 050 * calendar user agent allows the recipient to save contact 051 * information based on the "ORGANIZER" or "ATTENDEE" properties, 052 * those calendar user agents SHOULD use any "EMAIL" property 053 * parameter value for the email address of the contact over any 054 * mailto: calendar user address specified as the value of the 055 * property. Calendar user agents SHOULD NOT include an "EMAIL" 056 * property parameter when its value matches the calendar user 057 * address specified as the value of the property. 058 * 059 * Example: 060 * 061 * ATTENDEE;CN=Cyrus Daboo;EMAIL=cyrus@example.com:mailto:opaque-toke 062 * n-1234@example.com 063 * </pre> 064 */ 065// FIXME this class has been taken from the ical4j's github repo, in a branch without the javax.mail dependency 066// to be removed as soon as ical4j 4.0 is released 067// ical4j is licensed under the BSD license 068@SuppressWarnings("all") 069public class Email extends Parameter { 070 071 private static final long serialVersionUID = 1L; 072 073 private static final String PARAMETER_NAME = "EMAIL"; 074 075 private final URI address; 076 077 public Email(String address) throws URISyntaxException { 078 this(Uris.create(Strings.unquote(address))); 079 } 080 081 public Email(URI address) { 082 super(PARAMETER_NAME, new Factory()); 083 this.address = address; 084 } 085 086 public URI getAddress() { 087 return address; 088 } 089 090 @Override 091 public String getValue() { 092 return Uris.decode(Strings.valueOf(getAddress())); 093 } 094 095 public static class Factory extends Content.Factory implements ParameterFactory<Email> { 096 private static final long serialVersionUID = 1L; 097 098 public Factory() { 099 super(PARAMETER_NAME); 100 } 101 102 @Override 103 public Email createParameter(final String value) { 104 try { 105 return new Email(value); 106 } catch (URISyntaxException e) { 107 throw new IllegalArgumentException(e); 108 } 109 } 110 } 111}