use of com.zimbra.cs.mailbox.MailServiceException in project zm-mailbox by Zimbra.
the class CreateLink method redo.
@Override
public void redo() throws Exception {
int mboxId = getMailboxId();
Mailbox mailbox = MailboxManager.getInstance().getMailboxById(mboxId);
try {
mailbox.createLink(getOperationContext(), mFolderId, mName, mOwnerId, mRemoteId);
} catch (MailServiceException e) {
if (e.getCode() == MailServiceException.ALREADY_EXISTS) {
if (mLog.isInfoEnabled()) {
mLog.info("Link " + mId + " already exists in mailbox " + mboxId);
}
} else {
throw e;
}
}
}
use of com.zimbra.cs.mailbox.MailServiceException in project zm-mailbox by Zimbra.
the class CreateNote method redo.
@Override
public void redo() throws Exception {
int mboxId = getMailboxId();
Mailbox mailbox = MailboxManager.getInstance().getMailboxById(mboxId);
try {
mailbox.createNote(getOperationContext(), mContent, mBounds, Color.fromMetadata(mColor), mFolderId);
} catch (MailServiceException e) {
String code = e.getCode();
if (code.equals(MailServiceException.ALREADY_EXISTS)) {
if (mLog.isInfoEnabled())
mLog.info("Note " + mId + " already exists in mailbox " + mboxId);
} else
throw e;
}
}
use of com.zimbra.cs.mailbox.MailServiceException in project zm-mailbox by Zimbra.
the class CalendarMailSender method sendPartial.
public static ItemId sendPartial(OperationContext octxt, Mailbox mbox, MimeMessage mm, List<Upload> uploads, ItemId origMsgId, String replyType, String identityId, com.zimbra.cs.account.DataSource dataSource, boolean replyToSender, boolean asAdmin) throws ServiceException {
ItemId id = null;
try {
if (dataSource == null) {
MailSender mailSender = getCalendarMailSender(mbox).setSendPartial(true);
if (asAdmin) {
mailSender.setSkipHeaderUpdate(true);
id = mailSender.sendMimeMessage(octxt, mbox, Boolean.FALSE, mm, uploads, origMsgId, replyType, null, replyToSender);
} else {
id = mailSender.sendMimeMessage(octxt, mbox, mm, uploads, origMsgId, replyType, identityId, replyToSender);
}
} else {
MailSender mailSender = mbox.getDataSourceMailSender(dataSource, true).setSendPartial(true);
id = mailSender.sendDataSourceMimeMessage(octxt, mbox, mm, uploads, origMsgId, replyType);
}
} catch (MailServiceException e) {
if (e.getCode().equals(MailServiceException.SEND_PARTIAL_ADDRESS_FAILURE)) {
ZimbraLog.calendar.info("Unable to send to some addresses: " + e);
} else {
throw e;
}
}
return id;
}
use of com.zimbra.cs.mailbox.MailServiceException in project zm-mailbox by Zimbra.
the class GalSearchControl method doLocalGalAccountSync.
private void doLocalGalAccountSync(GalSearchResultCallback callback, Mailbox mbox, OperationContext octxt, int changeId, Set<Integer> folderIds, String syncToken, int limit, String filterAttr, String filterValue) throws ServiceException {
ZimbraLog.gal.info("Using limit %d for gal account sync", limit);
Pair<List<Integer>, TypedIdList> changed = mbox.getModifiedItems(octxt, changeId, 0, MailItem.Type.CONTACT, folderIds, -1, limit);
int count = 0;
boolean hasMore = false;
for (int itemId : changed.getFirst()) {
try {
MailItem item = mbox.getItemById(octxt, itemId, MailItem.Type.CONTACT);
if (item instanceof Contact) {
Contact c = (Contact) item;
if (filterAttr != null && !filterValue.equals(c.get(filterAttr))) {
continue;
}
callback.handleContact(c);
count++;
if (count % 100 == 0) {
ZimbraLog.gal.trace("processing #%s", count);
}
changeId = item.getModifiedSequence();
if (count == limit) {
hasMore = true;
break;
}
}
} catch (MailServiceException mse) {
if (MailServiceException.NO_SUCH_ITEM.equals(mse.getId())) {
ZimbraLog.gal.warn("skipping item %d due to no such item; probably deleted during sync", itemId, mse);
} else {
throw mse;
}
}
}
GalSyncToken newToken = new GalSyncToken(syncToken, mbox.getAccountId(), changeId);
ZimbraLog.gal.debug("computing new sync token for %s:%s", mbox.getAccountId(), newToken);
callback.setNewToken(newToken);
callback.setHasMoreResult(hasMore);
}
use of com.zimbra.cs.mailbox.MailServiceException 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));
}
}
Aggregations