Search in sources :

Example 1 with XProperty

use of net.fortuna.ical4j.model.property.XProperty in project zm-mailbox by Zimbra.

the class ZoneInfo2iCalendar method toVTimeZonePropertyList.

private static PropertyList toVTimeZonePropertyList(ZoneLine zline, LastModified lastModified, Set<String> tzAliases, boolean isPrimary, Integer matchScore) {
    PropertyList vtzProps = new PropertyList();
    vtzProps.add(new TzId(zline.getName()));
    vtzProps.add(lastModified);
    if (isPrimary) {
        vtzProps.add(new XProperty(TZIDMapper.X_ZIMBRA_TZ_PRIMARY, "TRUE"));
    }
    if (matchScore != null) {
        vtzProps.add(new XProperty(TZIDMapper.X_ZIMBRA_TZ_MATCH_SCORE, matchScore.toString()));
    }
    if (tzAliases != null) {
        for (String alias : tzAliases) {
            vtzProps.add(new XProperty(TZIDMapper.X_ZIMBRA_TZ_ALIAS, alias));
        }
    }
    return vtzProps;
}
Also used : PropertyList(net.fortuna.ical4j.model.PropertyList) XProperty(net.fortuna.ical4j.model.property.XProperty) TzId(net.fortuna.ical4j.model.property.TzId)

Example 2 with XProperty

use of net.fortuna.ical4j.model.property.XProperty in project zm-mailbox by Zimbra.

the class DefaultTnefToICalendar method addAttendees.

/**
     * 
     * @param icalOutput
     * @param mimeMsg
     * @param partstat
     * @param replyWanted
     * @throws ParserException
     * @throws URISyntaxException
     * @throws IOException
     * @throws ParseException
     * @throws MessagingException
     */
private void addAttendees(ContentHandler icalOutput, MimeMessage mimeMsg, PartStat partstat, boolean replyWanted) throws ParserException, URISyntaxException, IOException, ParseException, MessagingException {
    // ATTENDEEs
    InternetAddress firstFromIA = null;
    String firstFromEmailAddr = null;
    // Use for SENT-BY if applicable
    String senderMailto = null;
    String senderCn = null;
    javax.mail.Address[] toRecips = null;
    javax.mail.Address[] ccRecips = null;
    javax.mail.Address[] bccRecips = null;
    javax.mail.Address[] msgFroms = null;
    javax.mail.Address msgSender = null;
    if (mimeMsg != null) {
        toRecips = mimeMsg.getRecipients(javax.mail.Message.RecipientType.TO);
        ccRecips = mimeMsg.getRecipients(javax.mail.Message.RecipientType.CC);
        bccRecips = mimeMsg.getRecipients(javax.mail.Message.RecipientType.BCC);
        msgFroms = mimeMsg.getFrom();
        msgSender = mimeMsg.getSender();
    }
    if (msgFroms != null) {
        if (msgFroms.length != 1) {
            sLog.debug(msgFroms.length + " From: recipients for " + method.getValue());
        }
        if (msgFroms.length >= 1) {
            firstFromIA = (InternetAddress) msgFroms[0];
            firstFromEmailAddr = firstFromIA.getAddress();
        }
        if (msgSender != null) {
            String senderAddr = msgSender.toString();
            if (msgSender instanceof InternetAddress) {
                InternetAddress senderIA = (InternetAddress) msgSender;
                senderAddr = senderIA.getAddress();
                senderCn = senderIA.getPersonal();
                if (!firstFromIA.equals(senderIA)) {
                    senderMailto = "Mailto:" + senderAddr;
                }
            }
        }
    }
    if (method.equals(Method.REPLY) || method.equals(Method.COUNTER)) {
        // from ATTENDEE to ORGANIZER
        if (toRecips != null) {
            if (toRecips.length != 1) {
                sLog.debug(toRecips.length + " To: recipients for " + method.getValue());
            }
            if (toRecips.length >= 1) {
                InternetAddress ia = (InternetAddress) toRecips[0];
                String email = ia.getAddress();
                String displayName = ia.getPersonal();
                icalOutput.startProperty(Property.ORGANIZER);
                icalOutput.propertyValue("Mailto:" + email);
                if (displayName != null) {
                    icalOutput.parameter(Parameter.CN, displayName);
                }
                icalOutput.endProperty(Property.ORGANIZER);
            }
        }
        if (firstFromEmailAddr != null) {
            String displayName = firstFromIA.getPersonal();
            icalOutput.startProperty(Property.ATTENDEE);
            icalOutput.propertyValue("Mailto:" + firstFromEmailAddr);
            if (displayName != null) {
                icalOutput.parameter(Parameter.CN, displayName);
            }
            icalOutput.parameter(Parameter.CUTYPE, CuType.INDIVIDUAL.getValue());
            if (partstat != null) {
                icalOutput.parameter(Parameter.PARTSTAT, partstat.getValue());
            }
            if (senderMailto != null) {
                icalOutput.parameter(Parameter.SENT_BY, senderMailto);
            }
            icalOutput.endProperty(Property.ATTENDEE);
        }
    } else {
        // ORGANIZER to ATTENDEEs - REQUEST or CANCEL
        InternetAddress organizerEmail = null;
        if (firstFromEmailAddr != null) {
            SentBy sentBy = null;
            Cn cn = null;
            if (senderMailto != null) {
                sentBy = new SentBy(senderMailto);
            }
            organizerEmail = firstFromIA;
            String displayName = firstFromIA.getPersonal();
            if ((displayName != null) && (!displayName.equals(firstFromEmailAddr))) {
                cn = new Cn(displayName);
            }
            Organizer organizer = new Organizer();
            organizer.setValue("Mailto:" + firstFromEmailAddr);
            if (cn != null) {
                organizer.getParameters().add(cn);
            }
            if (sentBy != null) {
                organizer.getParameters().add(sentBy);
            }
            IcalUtil.addProperty(icalOutput, organizer);
            if (icalType == ICALENDAR_TYPE.VEVENT) {
                // Assumption - ORGANIZER is an attendee and is attending.
                Attendee attendee = new Attendee("Mailto:" + firstFromEmailAddr);
                if (cn != null) {
                    attendee.getParameters().add(cn);
                }
                attendee.getParameters().add(CuType.INDIVIDUAL);
                attendee.getParameters().add(Role.REQ_PARTICIPANT);
                if (!method.equals(Method.CANCEL)) {
                    PartStat orgPartstat = PartStat.ACCEPTED;
                    if (ccRecips != null) {
                        for (Address a : ccRecips) {
                            InternetAddress ia = (InternetAddress) a;
                            if (organizerEmail.equals(ia)) {
                                orgPartstat = PartStat.TENTATIVE;
                                break;
                            }
                        }
                    }
                    attendee.getParameters().add(orgPartstat);
                }
                // Was including SENT-BY but probably not appropriate
                // for a request
                IcalUtil.addProperty(icalOutput, attendee);
            }
        }
        if (toRecips != null) {
            for (Address a : toRecips) {
                InternetAddress ia = (InternetAddress) a;
                if ((organizerEmail != null) && organizerEmail.equals(ia)) {
                    // No need to add the information twice
                    continue;
                }
                addAttendee(icalOutput, ia, Role.REQ_PARTICIPANT, CuType.INDIVIDUAL, partstat, replyWanted);
            }
        }
        if (ccRecips != null) {
            for (Address a : ccRecips) {
                InternetAddress ia = (InternetAddress) a;
                if ((organizerEmail != null) && organizerEmail.equals(ia)) {
                    // No need to add the information twice
                    continue;
                }
                addAttendee(icalOutput, ia, Role.OPT_PARTICIPANT, CuType.INDIVIDUAL, partstat, replyWanted);
            }
        }
        if (bccRecips != null) {
            for (Address a : bccRecips) {
                InternetAddress ia = (InternetAddress) a;
                addAttendee(icalOutput, ia, Role.NON_PARTICIPANT, CuType.RESOURCE, partstat, replyWanted);
            }
        }
    }
    if (senderMailto != null) {
        XProperty msOlkSender = new XProperty("X-MS-OLK-SENDER", senderMailto);
        if (senderCn != null) {
            Cn cn = new Cn(senderCn);
            msOlkSender.getParameters().add(cn);
        }
        IcalUtil.addProperty(icalOutput, msOlkSender);
    }
}
Also used : Address(javax.mail.Address) InternetAddress(javax.mail.internet.InternetAddress) XProperty(net.fortuna.ical4j.model.property.XProperty) Address(javax.mail.Address) InternetAddress(javax.mail.internet.InternetAddress) Organizer(net.fortuna.ical4j.model.property.Organizer) SentBy(net.fortuna.ical4j.model.parameter.SentBy) PartStat(net.fortuna.ical4j.model.parameter.PartStat) Cn(net.fortuna.ical4j.model.parameter.Cn) Attendee(net.fortuna.ical4j.model.property.Attendee)

Aggregations

XProperty (net.fortuna.ical4j.model.property.XProperty)2 Address (javax.mail.Address)1 InternetAddress (javax.mail.internet.InternetAddress)1 PropertyList (net.fortuna.ical4j.model.PropertyList)1 Cn (net.fortuna.ical4j.model.parameter.Cn)1 PartStat (net.fortuna.ical4j.model.parameter.PartStat)1 SentBy (net.fortuna.ical4j.model.parameter.SentBy)1 Attendee (net.fortuna.ical4j.model.property.Attendee)1 Organizer (net.fortuna.ical4j.model.property.Organizer)1 TzId (net.fortuna.ical4j.model.property.TzId)1