Search in sources :

Example 51 with Metadata

use of com.zimbra.cs.mailbox.Metadata in project zm-mailbox by Zimbra.

the class DbTag method asUnderlyingData.

private static UnderlyingData asUnderlyingData(ResultSet rs) throws SQLException, ServiceException {
    UnderlyingData data = new UnderlyingData();
    data.id = rs.getInt(1);
    data.type = MailItem.Type.TAG.toByte();
    data.folderId = Mailbox.ID_FOLDER_TAGS;
    data.name = rs.getString(2);
    data.size = rs.getInt(4);
    data.unreadCount = rs.getInt(5);
    boolean listed = rs.getBoolean(6);
    String policy = rs.getString(8);
    RetentionPolicy rp = policy == null ? null : RetentionPolicyManager.retentionPolicyFromMetadata(new Metadata(policy), true);
    long c = rs.getLong(3);
    Color color = rs.wasNull() ? null : Color.fromMetadata(c);
    // FIXME: if Tag weren't a subclass of MailItem, this step wouldn't be necessary
    data.metadata = Tag.encodeMetadata(color, 1, 1, rp, listed);
    data.modMetadata = rs.getInt(7);
    data.modContent = data.modMetadata;
    return data;
}
Also used : UnderlyingData(com.zimbra.cs.mailbox.MailItem.UnderlyingData) Color(com.zimbra.common.mailbox.Color) Metadata(com.zimbra.cs.mailbox.Metadata) RetentionPolicy(com.zimbra.soap.mail.type.RetentionPolicy)

Example 52 with Metadata

use of com.zimbra.cs.mailbox.Metadata in project zm-mailbox by Zimbra.

the class Invite method decodeMetadata.

/**
     * This API is public for RedoLogging to call into it -- you probably don't want to call it from
     * anywhere else!
     *
     * @param mailboxId
     * @param meta
     * @param calItem
     * @param accountTZ
     * @return
     * @throws ServiceException
     */
public static Invite decodeMetadata(int mailboxId, Metadata meta, CalendarItem calItem, ICalTimeZone accountTZ) throws ServiceException {
    byte btype = (byte) meta.getLong(FN_ITEMTYPE, -1);
    MailItem.Type type = btype >= 0 ? MailItem.Type.of(btype) : MailItem.Type.APPOINTMENT;
    String uid = meta.get(FN_UID, null);
    int mailItemId = (int) meta.getLong(FN_INVMSGID);
    int componentNum = (int) meta.getLong(FN_COMPNUM);
    String classProp = meta.get(FN_CLASS, IcalXmlStrMap.CLASS_PUBLIC);
    boolean classPropSetByMe = meta.getBool(FN_CLASS_SETBYME, false);
    String status = meta.get(FN_STATUS, IcalXmlStrMap.STATUS_CONFIRMED);
    String freebusy = meta.get(FN_APPT_FREEBUSY, null);
    String transp = meta.get(FN_TRANSP, IcalXmlStrMap.TRANSP_OPAQUE);
    boolean sentByMe = meta.getBool(FN_SENTBYME);
    String fragment = meta.get(FN_FRAGMENT, "");
    // default to false for backward compat
    boolean descInMeta = meta.getBool(FN_DESC_IN_META, false);
    String desc = descInMeta ? meta.get(FN_DESC, null) : null;
    String descHtml = descInMeta ? meta.get(FN_DESC_HTML, null) : null;
    long completed = meta.getLong(FN_COMPLETED, 0);
    ParsedDateTime dtStart = null;
    ParsedDateTime dtEnd = null;
    ParsedDuration duration = null;
    RecurId recurrenceId = null;
    TimeZoneMap tzMap = Util.decodeFromMetadata(meta.getMap(FN_TZMAP), accountTZ);
    Metadata metaRecur = meta.getMap(FN_RECURRENCE, true);
    Recurrence.IRecurrence recurrence = null;
    if (metaRecur != null) {
        recurrence = Recurrence.decodeMetadata(metaRecur, tzMap);
    }
    String methodStr = meta.get(FN_METHOD, ICalTok.PUBLISH.toString());
    if (ICalTok.CANCEL.toString().equals(methodStr))
        status = IcalXmlStrMap.STATUS_CANCELLED;
    int flags = (int) meta.getLong(FN_APPT_FLAGS, 0);
    try {
        // DtStart
        dtStart = ParsedDateTime.parse(meta.get(FN_START, null), tzMap);
        // DtEnd
        dtEnd = ParsedDateTime.parse(meta.get(FN_END, null), tzMap);
        if ((flags & APPT_FLAG_ALLDAY) != 0) {
            // Fixup historic data with incorrect all-day start/end format.
            if (dtStart != null)
                dtStart.forceDateOnly();
            if (dtEnd != null)
                dtEnd.forceDateOnly();
        }
        // Duration
        duration = ParsedDuration.parse(meta.get(FN_DURATION, null));
        if (meta.containsKey(FN_RECUR_ID)) {
            Metadata rdata = meta.getMap(FN_RECUR_ID);
            recurrenceId = RecurId.decodeMetadata(rdata, tzMap);
        }
    } catch (ParseException e) {
        throw ServiceException.FAILURE(String.format("Error parsing metadata for invite %s-%s in calItem %s", mailItemId, componentNum, (calItem != null) ? Integer.toString(calItem.getId()) : "(null)"), e);
    }
    String name = meta.get(FN_NAME, "");
    String loc = meta.get(FN_LOCATION, null);
    // For existing invites with no partstat, default to ACCEPTED status.
    String partStat = meta.get(FN_PARTSTAT, IcalXmlStrMap.PARTSTAT_ACCEPTED);
    // For existing invites with no RSVP, default to true.
    boolean rsvp = meta.getBool(FN_RSVP, true);
    long dtstamp = meta.getLong(FN_DTSTAMP, 0);
    long lastModified = meta.getLong(FN_LAST_MODIFIED, 0);
    int seqno = (int) meta.getLong(FN_SEQ_NO, 0);
    int lastFullSeqno = (int) meta.getLong(FN_LAST_FULL_SEQ_NO, seqno);
    ZOrganizer org = null;
    try {
        Metadata metaOrg = meta.getMap(FN_ORGANIZER, true);
        org = metaOrg != null ? new ZOrganizer(metaOrg) : null;
    } catch (ServiceException e) {
        sLog.warn("Problem decoding organizer for calItem %s invite %s-%s", (calItem != null) ? Integer.toString(calItem.getId()) : "(null)", mailItemId, componentNum);
    }
    long numAts = meta.getLong(FN_NUM_ATTENDEES, 0);
    ArrayList<ZAttendee> attendees = new ArrayList<ZAttendee>((int) numAts);
    for (int i = 0; i < numAts; i++) {
        try {
            Metadata metaAttendee = meta.getMap(FN_ATTENDEE + i, true);
            if (metaAttendee != null)
                attendees.add(new ZAttendee(metaAttendee));
        } catch (ServiceException e) {
            ZimbraLog.calendar.warn("Problem decoding attendee %s for calendar item %s invite %s-%s", i, (calItem != null) ? Integer.toString(calItem.getId()) : "(null)", mailItemId, componentNum);
        }
    }
    boolean isOrganizer = false;
    if (meta.containsKey(FN_IS_ORGANIZER)) {
        isOrganizer = meta.getBool(FN_IS_ORGANIZER);
    } else {
        // backward compat for invites created before FN_IS_ORGANIZER was introduced
        if (org != null) {
            String orgAddr = org.getAddress();
            Account account = MailboxManager.getInstance().getMailboxById(mailboxId).getAccount();
            AccountAddressMatcher acctMatcher = new AccountAddressMatcher(account);
            isOrganizer = acctMatcher.matches(orgAddr);
        } else {
            // If there are other attendees, it's an Outlook POP/IMAP bug.  If not,
            // it's a properly formatted single-user event.  See isOrganizer()
            // method for more info.
            isOrganizer = numAts < 1;
        }
    }
    String priority = meta.get(FN_PRIORITY, null);
    String pctComplete = meta.get(FN_PCT_COMPLETE, null);
    List<String> comments = null;
    int numComm = (int) meta.getLong(FN_NUM_COMMENTS, 0);
    if (numComm > 0) {
        comments = new ArrayList<String>(numComm);
        for (int i = 0; i < numComm; i++) {
            String comm = meta.get(FN_COMMENT + i, null);
            if (comm != null)
                comments.add(comm);
        }
    }
    List<String> contacts = null;
    int numContacts = (int) meta.getLong(FN_NUM_CONTACTS, 0);
    if (numContacts > 0) {
        contacts = new ArrayList<String>(numContacts);
        for (int i = 0; i < numContacts; i++) {
            String contact = meta.get(FN_CONTACT + i, null);
            if (contact != null)
                contacts.add(contact);
        }
    }
    List<String> categories = null;
    int numCat = (int) meta.getLong(FN_NUM_CATEGORIES, 0);
    if (numCat > 0) {
        categories = new ArrayList<String>(numCat);
        for (int i = 0; i < numCat; i++) {
            String cat = meta.get(FN_CATEGORY + i, null);
            if (cat != null)
                categories.add(cat);
        }
    }
    Geo geo = null;
    Metadata metaGeo = meta.getMap(FN_GEO, true);
    if (metaGeo != null)
        geo = Util.decodeGeoFromMetadata(metaGeo);
    String url = meta.get(FN_URL, null);
    Invite invite = new Invite(type, methodStr, tzMap, calItem, uid, status, priority, pctComplete, completed, freebusy, transp, classProp, dtStart, dtEnd, duration, recurrence, isOrganizer, org, attendees, name, loc, flags, partStat, rsvp, recurrenceId, dtstamp, lastModified, seqno, lastFullSeqno, mailboxId, mailItemId, componentNum, sentByMe, desc, descHtml, fragment, comments, categories, contacts, geo, url);
    // a little hacky, but necessary
    invite.mDescInMeta = descInMeta;
    invite.setClassPropSetByMe(classPropSetByMe);
    long numAlarms = meta.getLong(FN_NUM_ALARMS, 0);
    for (int i = 0; i < numAlarms; i++) {
        try {
            Metadata metaAlarm = meta.getMap(FN_ALARM + i, true);
            if (metaAlarm != null) {
                Alarm alarm = Alarm.decodeMetadata(metaAlarm);
                if (alarm != null)
                    invite.addAlarm(alarm);
            }
        } catch (ServiceException e) {
            ZimbraLog.calendar.warn("Problem decoding alarm %s for calendar item %s invite %s-%s", i, (calItem != null) ? Integer.toString(calItem.getId()) : "(null)", mailItemId, componentNum, e);
        }
    }
    List<ZProperty> xprops = Util.decodeXPropsFromMetadata(meta);
    if (xprops != null) {
        for (ZProperty xprop : xprops) {
            boolean isHtmlDesc = false;
            if (ICalTok.X_ALT_DESC.equals(xprop.getToken())) {
                // Backward compat.  We used to save X-ALT-DESC property as an x-prop.  Now we use it
                // for HTML description, when FMTTYPE=text/html.
                ZParameter fmttype = xprop.getParameter(ICalTok.FMTTYPE);
                if (fmttype != null && MimeConstants.CT_TEXT_HTML.equalsIgnoreCase(fmttype.getValue())) {
                    isHtmlDesc = true;
                    invite.mDescHtml = xprop.getValue();
                }
            }
            if (!isHtmlDesc)
                invite.addXProp(xprop);
        }
    }
    invite.setDontIndexMimeMessage(meta.getBool(FN_DONT_INDEX_MM, false));
    boolean localOnly = meta.getBool(FN_LOCAL_ONLY, false);
    invite.setLocalOnly(localOnly);
    invite.sanitize(false);
    return invite;
}
Also used : IRecurrence(com.zimbra.cs.mailbox.calendar.Recurrence.IRecurrence) Account(com.zimbra.cs.account.Account) ParsedDuration(com.zimbra.common.calendar.ParsedDuration) IRecurrence(com.zimbra.cs.mailbox.calendar.Recurrence.IRecurrence) Metadata(com.zimbra.cs.mailbox.Metadata) ArrayList(java.util.ArrayList) TimeZoneMap(com.zimbra.common.calendar.TimeZoneMap) ParsedDateTime(com.zimbra.common.calendar.ParsedDateTime) ZParameter(com.zimbra.common.calendar.ZCalendar.ZParameter) Geo(com.zimbra.common.calendar.Geo) MailItem(com.zimbra.cs.mailbox.MailItem) ServiceException(com.zimbra.common.service.ServiceException) AccountAddressMatcher(com.zimbra.cs.util.AccountUtil.AccountAddressMatcher) ZProperty(com.zimbra.common.calendar.ZCalendar.ZProperty) ParseException(java.text.ParseException)

Example 53 with Metadata

use of com.zimbra.cs.mailbox.Metadata in project zm-mailbox by Zimbra.

the class Util method encodeAsMetadata.

public static Metadata encodeAsMetadata(ICalTimeZone tz) {
    Metadata meta = new Metadata();
    String tzid = tz.getID();
    meta.put(FN_TZID, tzid);
    // For well-known time zone we only need the TZID.
    if (ICalTimeZone.lookupByTZID(tzid) != null)
        return meta;
    meta.put(FN_STANDARD_OFFSET, tz.getStandardOffset());
    meta.put(FN_DAYTOSTD_DTSTART, tz.getStandardDtStart());
    meta.put(FN_DAYTOSTD_RULE, tz.getStandardRule());
    meta.put(FN_STANDARD_TZNAME, tz.getStandardTzname());
    meta.put(FN_DAYLIGHT_OFFSET, tz.getDaylightOffset());
    meta.put(FN_STDTODAY_DTSTART, tz.getDaylightDtStart());
    meta.put(FN_STDTODAY_RULE, tz.getDaylightRule());
    meta.put(FN_DAYLIGHT_TZNAME, tz.getDaylightTzname());
    return meta;
}
Also used : Metadata(com.zimbra.cs.mailbox.Metadata)

Example 54 with Metadata

use of com.zimbra.cs.mailbox.Metadata in project zm-mailbox by Zimbra.

the class Util method encodeXParamsAsMetadata.

public static void encodeXParamsAsMetadata(Metadata meta, Iterator<ZParameter> xparamsIter) {
    int xparamCount = 0;
    for (; xparamsIter.hasNext(); ) {
        ZParameter xparam = xparamsIter.next();
        String paramName = xparam.getName();
        if (paramName == null)
            continue;
        Metadata paramMeta = new Metadata();
        paramMeta.put(FN_NAME, paramName);
        String paramValue = xparam.getValue();
        if (paramValue != null)
            paramMeta.put(FN_VALUE, paramValue);
        meta.put(FN_XPROP_OR_XPARAM + xparamCount, paramMeta);
        xparamCount++;
    }
    if (xparamCount > 0)
        meta.put(FN_NUM_XPROPS_OR_XPARAMS, xparamCount);
}
Also used : Metadata(com.zimbra.cs.mailbox.Metadata) ZParameter(com.zimbra.common.calendar.ZCalendar.ZParameter)

Example 55 with Metadata

use of com.zimbra.cs.mailbox.Metadata in project zm-mailbox by Zimbra.

the class InviteInfo method encodeMetadata.

public Metadata encodeMetadata() {
    Metadata md = new Metadata();
    md.put(FN_MSGID, mMsgId);
    md.put(FN_COMPNUM, mComponentId);
    if (mRecurrenceId != null) {
        md.put(FN_RECURRENCEID, mRecurrenceId.encodeMetadata());
    }
    if (mMethod.equals(ICalTok.CANCEL.toString())) {
        md.put(FN_METHOD, METHOD_CANCEL);
    } else {
        md.put(FN_METHOD, METHOD_REQUEST);
    }
    return md;
}
Also used : Metadata(com.zimbra.cs.mailbox.Metadata)

Aggregations

Metadata (com.zimbra.cs.mailbox.Metadata)60 Mailbox (com.zimbra.cs.mailbox.Mailbox)16 ArrayList (java.util.ArrayList)15 ServiceException (com.zimbra.common.service.ServiceException)13 DbConnection (com.zimbra.cs.db.DbPool.DbConnection)9 SQLException (java.sql.SQLException)9 IOException (java.io.IOException)8 PreparedStatement (java.sql.PreparedStatement)8 ResultSet (java.sql.ResultSet)8 OperationContext (com.zimbra.cs.mailbox.OperationContext)7 ICalTimeZone (com.zimbra.common.calendar.ICalTimeZone)6 MailItem (com.zimbra.cs.mailbox.MailItem)5 HashMap (java.util.HashMap)5 ZParameter (com.zimbra.common.calendar.ZCalendar.ZParameter)4 DataSource (com.zimbra.cs.account.DataSource)4 DbDataSource (com.zimbra.cs.db.DbDataSource)4 DataSourceItem (com.zimbra.cs.db.DbDataSource.DataSourceItem)4 Map (java.util.Map)4 Entry (java.util.Map.Entry)4 ParsedDateTime (com.zimbra.common.calendar.ParsedDateTime)3