use of com.zimbra.common.calendar.ZCalendar.ZVCalendar in project zm-mailbox by Zimbra.
the class GetMsgTest method testHandle.
@Test
public void testHandle() throws Exception {
Account acct1 = Provisioning.getInstance().get(Key.AccountBy.name, "test@zimbra.com");
Account acct2 = Provisioning.getInstance().get(Key.AccountBy.name, "test2@zimbra.com");
Mailbox mbox1 = MailboxManager.getInstance().getMailboxByAccount(acct1);
Folder calendarFolder = mbox1.getCalendarFolders(null, SortBy.NONE).get(0);
String fragment = "Some message";
ZVCalendar calendar = new ZVCalendar();
calendar.addDescription(desc, null);
ZComponent comp = new ZComponent("VEVENT");
calendar.addComponent(comp);
Invite invite = MailboxTestUtil.generateInvite(acct1, fragment, calendar);
ICalTimeZone ical = invite.getTimeZoneMap().getLocalTimeZone();
long utc = 5 * 60 * 60 * 1000;
ParsedDateTime s = ParsedDateTime.fromUTCTime(System.currentTimeMillis() + utc, ical);
ParsedDateTime e = ParsedDateTime.fromUTCTime(System.currentTimeMillis() + (30 * 60 * 1000) + utc, ical);
invite.setDtStart(s);
invite.setDtEnd(e);
invite.setPriority("5");
invite.setClassProp("PRI");
invite.setOrganizer(new ZOrganizer("test@zimbra.com", null));
invite.setUid(UUID.randomUUID().toString());
invite.setMethod("REQUEST");
invite.setName("Testing");
invite.setFreeBusy("B");
invite.setIsOrganizer(true);
invite.setItemType(MailItem.Type.APPOINTMENT);
invite.setUid(UUID.randomUUID().toString());
AddInviteData inviteData = mbox1.addInvite(null, invite, calendarFolder.getId());
calendarFolder = mbox1.getCalendarFolders(null, SortBy.NONE).get(0);
Element request = new Element.XMLElement("GetCalendarItem");
Element action = request.addElement(MailConstants.E_MSG);
action.addAttribute(MailConstants.A_ID, acct1.getId() + ":" + inviteData.calItemId + "-" + inviteData.invId);
action.addAttribute(MailConstants.A_WANT_HTML, "1");
action.addAttribute(MailConstants.A_NEED_EXP, "1");
Element response = new GetMsg().handle(request, ServiceTestUtil.getRequestContext(acct1));
Element organizer = response.getElement("m").getElement("inv").getElement("comp").getElement("or");
String organizerString = organizer.prettyPrint();
assertTrue(organizerString.contains("a=\"test@zimbra.com\" url=\"test@zimbra.com\""));
mbox1.grantAccess(null, 10, acct2.getId(), ACL.GRANTEE_USER, ACL.RIGHT_READ, null);
request = new Element.XMLElement("CreateMountPoint");
Element link = request.addElement("link");
link.addAttribute("f", "#");
link.addAttribute("reminder", 0);
link.addAttribute("name", "sharedcal");
link.addAttribute("path", "/Calendar");
link.addAttribute("owner", "test@zimbra.com");
link.addAttribute("l", 10);
link.addAttribute("view", "appoinment");
response = new CreateMountpoint().handle(request, ServiceTestUtil.getRequestContext(acct2));
String mptId = response.getElement("link").getAttribute("id");
request = new Element.XMLElement("GetMsgRequest");
action = request.addElement(MailConstants.E_MSG);
action.addAttribute(MailConstants.A_ID, acct1.getId() + ":" + inviteData.calItemId + "-" + mptId);
action.addAttribute(MailConstants.A_WANT_HTML, "1");
action.addAttribute(MailConstants.A_NEED_EXP, "1");
response = new GetMsg().handle(request, ServiceTestUtil.getRequestContext(acct2, acct1));
organizerString = response.getElement("m").prettyPrint();
assertTrue(!organizerString.contains("a=\"test@zimbra.com\" url=\"test@zimbra.com\""));
request = new Element.XMLElement("FolderAction");
action = request.addElement("action");
action.addAttribute("id", mptId);
action.addAttribute("op", "delete");
response = new FolderAction().handle(request, ServiceTestUtil.getRequestContext(acct2));
mbox1.revokeAccess(null, 10, acct2.getId());
}
use of com.zimbra.common.calendar.ZCalendar.ZVCalendar in project zm-mailbox by Zimbra.
the class IcsImportParseHandler method startCalendar.
@Override
public void startCalendar() throws ParserException {
mComponents.clear();
mInZCalendar = true;
mCurCal = new ZVCalendar();
mMethod = ICalTok.PUBLISH.toString();
mTimeZoneMap = new TimeZoneMap(Util.getAccountTimeZone(mAccount));
}
use of com.zimbra.common.calendar.ZCalendar.ZVCalendar in project zm-mailbox by Zimbra.
the class Invite method newToICalendar.
public ZVCalendar newToICalendar(boolean useOutlookCompatMode, boolean includePrivateData) throws ServiceException {
ZVCalendar vcal = new ZVCalendar();
vcal.addVersionAndProdId();
vcal.addProperty(new ZProperty(ICalTok.METHOD, mMethod.toString()));
// timezones
if (!isAllDayEvent() || useOutlookCompatMode) {
// Don't write any VTIMEZONE for all-day appointments.
for (Iterator<ICalTimeZone> iter = mTzMap.tzIterator(); iter.hasNext(); ) {
ICalTimeZone cur = iter.next();
vcal.addComponent(cur.newToVTimeZone());
}
}
vcal.addComponent(newToVComponent(useOutlookCompatMode, includePrivateData));
return vcal;
}
use of com.zimbra.common.calendar.ZCalendar.ZVCalendar in project zm-mailbox by Zimbra.
the class ArchiveFormatter method addData.
private void addData(UserServletContext context, Folder fldr, Map<Object, Folder> fmap, Set<MailItem.Type> types, Resolve r, boolean timestamp, ArchiveInputStream ais, ArchiveInputEntry aie, List<ServiceException> errs) throws ServiceException {
try {
int defaultFldr;
Mailbox mbox = fldr.getMailbox();
String dir, file;
String name = aie.getName();
int idx = name.lastIndexOf('/');
MailItem newItem = null, oldItem;
OperationContext oc = context.opContext;
BufferedReader reader;
MailItem.Type type, view;
if (idx == -1) {
file = name;
dir = "";
} else {
file = name.substring(idx + 1);
dir = name.substring(0, idx + 1);
if (!dir.startsWith("/"))
dir = '/' + dir;
}
if (file.length() == 0) {
return;
} else if (file.endsWith(".csv") || file.endsWith(".vcf")) {
defaultFldr = Mailbox.ID_FOLDER_CONTACTS;
type = MailItem.Type.CONTACT;
view = MailItem.Type.CONTACT;
} else if (file.endsWith(".eml")) {
defaultFldr = Mailbox.ID_FOLDER_INBOX;
type = MailItem.Type.MESSAGE;
view = MailItem.Type.MESSAGE;
} else if (file.endsWith(".ics")) {
if (dir.startsWith("Tasks/")) {
defaultFldr = Mailbox.ID_FOLDER_TASKS;
type = MailItem.Type.TASK;
view = MailItem.Type.TASK;
} else {
defaultFldr = Mailbox.ID_FOLDER_CALENDAR;
type = MailItem.Type.APPOINTMENT;
view = MailItem.Type.APPOINTMENT;
}
} else if (file.endsWith(".wiki")) {
defaultFldr = Mailbox.ID_FOLDER_NOTEBOOK;
type = MailItem.Type.WIKI;
view = MailItem.Type.WIKI;
} else {
defaultFldr = Mailbox.ID_FOLDER_BRIEFCASE;
type = MailItem.Type.DOCUMENT;
view = MailItem.Type.DOCUMENT;
}
if (types != null && !types.contains(type)) {
return;
}
if (dir.equals("")) {
if (fldr.getPath().equals("/")) {
fldr = mbox.getFolderById(oc, defaultFldr);
}
if (fldr.getDefaultView() != MailItem.Type.UNKNOWN && fldr.getDefaultView() != view && !((view == MailItem.Type.DOCUMENT || view == MailItem.Type.WIKI) && (fldr.getDefaultView() == MailItem.Type.DOCUMENT || fldr.getDefaultView() == MailItem.Type.WIKI))) {
throw FormatterServiceException.INVALID_TYPE(view.toString(), fldr.getPath());
}
} else {
String s = fldr.getPath();
if (!s.endsWith("/"))
s += '/';
if (dir.startsWith(s))
dir = dir.substring(s.length());
fldr = createPath(context, fmap, fldr.getPath() + dir, view);
}
switch(type) {
case APPOINTMENT:
case TASK:
boolean continueOnError = context.ignoreAndContinueOnError();
boolean preserveExistingAlarms = context.preserveAlarms();
InputStream is = ais.getInputStream();
try {
if (aie.getSize() <= LC.calendar_ics_import_full_parse_max_size.intValue()) {
List<ZVCalendar> icals = ZCalendarBuilder.buildMulti(is, UTF8);
ImportInviteVisitor visitor = new ImportInviteVisitor(oc, fldr, preserveExistingAlarms);
Invite.createFromCalendar(context.targetAccount, null, icals, true, continueOnError, visitor);
} else {
ZICalendarParseHandler handler = new IcsImportParseHandler(oc, context.targetAccount, fldr, continueOnError, preserveExistingAlarms);
ZCalendarBuilder.parse(is, UTF8, handler);
}
} finally {
is.close();
}
break;
case CONTACT:
if (file.endsWith(".csv")) {
reader = new BufferedReader(new InputStreamReader(ais.getInputStream(), UTF8));
ImportContacts.ImportCsvContacts(oc, context.targetMailbox, new ItemId(fldr), ContactCSV.getContacts(reader, null));
} else {
List<VCard> cards = VCard.parseVCard(new String(readArchiveEntry(ais, aie), UTF8));
if (cards == null || cards.size() == 0 || (cards.size() == 1 && cards.get(0).fields.isEmpty())) {
addError(errs, FormatterServiceException.MISSING_VCARD_FIELDS(name));
return;
}
for (VCard vcf : cards) {
if (vcf.fields.isEmpty())
continue;
mbox.createContact(oc, vcf.asParsedContact(), fldr.getId(), null);
}
}
break;
case DOCUMENT:
case WIKI:
String creator = context.getAuthAccount() == null ? null : context.getAuthAccount().getName();
try {
oldItem = mbox.getItemByPath(oc, file, fldr.getId());
if (oldItem.getType() != type) {
addError(errs, FormatterServiceException.MISMATCHED_TYPE(name));
} else if (r == Resolve.Replace) {
mbox.delete(oc, oldItem.getId(), type);
throw MailServiceException.NO_SUCH_ITEM(oldItem.getId());
} else if (r != Resolve.Skip) {
newItem = mbox.addDocumentRevision(oc, oldItem.getId(), creator, oldItem.getName(), null, ais.getInputStream());
}
} catch (NoSuchItemException e) {
if (type == MailItem.Type.WIKI) {
newItem = mbox.createWiki(oc, fldr.getId(), file, creator, null, ais.getInputStream());
} else {
newItem = mbox.createDocument(oc, fldr.getId(), file, null, creator, null, ais.getInputStream());
}
}
if (newItem != null) {
if (timestamp)
mbox.setDate(oc, newItem.getId(), type, aie.getModTime());
}
break;
case MESSAGE:
int flags = aie.isUnread() ? Flag.BITMASK_UNREAD : 0;
DeliveryOptions opt = new DeliveryOptions().setFolderId(fldr.getId()).setNoICal(true).setFlags(flags);
mbox.addMessage(oc, ais.getInputStream(), (int) aie.getSize(), timestamp ? aie.getModTime() : ParsedMessage.DATE_HEADER, opt, null);
break;
}
} catch (Exception e) {
if (e instanceof MailServiceException && ((MailServiceException) e).getCode() == MailServiceException.QUOTA_EXCEEDED)
throw (MailServiceException) e;
else
addError(errs, FormatterServiceException.UNKNOWN_ERROR(aie.getName(), e));
}
}
use of com.zimbra.common.calendar.ZCalendar.ZVCalendar in project zm-mailbox by Zimbra.
the class IcsFormatter method saveCallback.
@Override
public void saveCallback(UserServletContext context, String contentType, Folder folder, String filename) throws UserServletException, ServiceException, IOException, ServletException {
boolean continueOnError = context.ignoreAndContinueOnError();
boolean preserveExistingAlarms = context.preserveAlarms();
InputStream is = context.getRequestInputStream(-1);
String charset = MimeConstants.P_CHARSET_UTF8;
String ctStr = context.req.getContentType();
if (ctStr != null) {
String cs = Mime.getCharset(ctStr);
if (cs != null)
charset = cs;
}
try {
if (context.req.getContentLength() <= LC.calendar_ics_import_full_parse_max_size.intValue()) {
// Build a list of ZVCalendar objects by fully parsing the ics file, then iterate them
// and add them one by one. Memory hungry if there are very many events/tasks, but it allows
// TZID reference before VTIMEZONE of that timezone appears in the ics file.
List<ZVCalendar> icals = ZCalendarBuilder.buildMulti(is, charset);
ImportInviteVisitor visitor = new ImportInviteVisitor(context.opContext, folder, preserveExistingAlarms);
Invite.createFromCalendar(context.targetAccount, null, icals, true, continueOnError, visitor);
} else {
// Events/tasks are added in callbacks during parse. This is more memory efficient than the
// other method, but it doesn't allow forward referencing TZIDs. ics files generated by
// clients that put VTIMEZONEs at the end will not parse. Evolution client does this.
ZICalendarParseHandler handler = new IcsImportParseHandler(context.opContext, context.targetAccount, folder, continueOnError, preserveExistingAlarms);
ZCalendarBuilder.parse(is, charset, handler);
}
} finally {
is.close();
}
}
Aggregations