use of com.zimbra.cs.account.DataSource in project zm-mailbox by Zimbra.
the class PlainTextSignature method preModify.
@Override
public void preModify(CallbackContext context, String attrName, Object value, Map attrsToModify, Entry entry) throws ServiceException {
SingleValueMod mod = singleValueMod(attrName, value);
if (mod.unsetting())
return;
Account account;
if (entry instanceof Account) {
account = (Account) entry;
} else if (entry instanceof Identity) {
account = ((Identity) entry).getAccount();
} else if (entry instanceof DataSource) {
account = ((DataSource) entry).getAccount();
} else {
return;
}
Signature sig = Provisioning.getInstance().get(account, Key.SignatureBy.id, mod.value());
if (sig == null) {
throw ServiceException.INVALID_REQUEST("No such signature " + mod.value() + " for account " + account.getName(), null);
}
String sigAttr = SignatureUtil.mimeTypeToAttrName(MimeConstants.CT_TEXT_PLAIN);
String plainSig = sig.getAttr(sigAttr, null);
if (StringUtil.isNullOrEmpty(plainSig)) {
throw ServiceException.INVALID_REQUEST("Signature " + mod.value() + " must have plain text content", null);
}
}
use of com.zimbra.cs.account.DataSource in project zm-mailbox by Zimbra.
the class Mailbox method updateRssDataSource.
/**
* Updates the data source for an RSS folder. If the folder URL is set,
* checks or creates a data source that updates the folder. If the URL
* is not set, deletes the data source if necessary.
*/
protected void updateRssDataSource(Folder folder) {
try {
Provisioning prov = Provisioning.getInstance();
Account account = getAccount();
DataSource ds = null;
List<DataSource> dataSources = prov.getAllDataSources(account);
for (DataSource i : dataSources) {
if (i.getFolderId() == folder.getId() && (i.getType() == DataSourceType.rss || i.getType() == DataSourceType.cal)) {
ds = i;
break;
}
}
if (StringUtil.isNullOrEmpty(folder.getUrl())) {
if (ds != null) {
// URL removed from folder.
String dsid = ds.getId();
prov.deleteDataSource(account, dsid);
DataSourceManager.cancelSchedule(account, dsid);
}
return;
}
// URL is not null or empty. Create data source if necessary.
if (ds == null) {
Map<String, Object> attrs = new HashMap<String, Object>();
attrs.put(Provisioning.A_zimbraDataSourceEnabled, LdapConstants.LDAP_TRUE);
attrs.put(Provisioning.A_zimbraDataSourceFolderId, Integer.toString(folder.getId()));
DataSourceType type;
String name;
if (folder.getDefaultView() == MailItem.Type.APPOINTMENT) {
type = DataSourceType.cal;
name = "CAL-" + folder.getId();
} else {
type = DataSourceType.rss;
name = "RSS-" + folder.getId();
}
ds = prov.createDataSource(account, type, name, attrs);
DataSourceManager.updateSchedule(account, ds);
}
} catch (ServiceException e) {
ZimbraLog.mailbox.warn("Unable to update data source for folder %s.", folder.getPath(), e);
}
}
use of com.zimbra.cs.account.DataSource in project zm-mailbox by Zimbra.
the class SoapProvisioning method getAllDataSources.
@Override
public List<DataSource> getAllDataSources(Account account) throws ServiceException {
List<DataSource> result = new ArrayList<DataSource>();
XMLElement req = new XMLElement(AdminConstants.GET_DATA_SOURCES_REQUEST);
req.addElement(AdminConstants.E_ID).setText(account.getId());
Element resp = invoke(req);
for (Element dataSource : resp.listElements(AccountConstants.E_DATA_SOURCE)) {
result.add(new SoapDataSource(account, dataSource, this));
}
return result;
}
use of com.zimbra.cs.account.DataSource in project zm-mailbox by Zimbra.
the class DbDataSource method getOldestConversationsUpToSize.
public static List<PurgeableConv> getOldestConversationsUpToSize(List<DataSource> dataSources, long targetSize, long startDate) throws ServiceException {
Mailbox mbox = DataSourceManager.getInstance().getMailbox(dataSources.get(0));
DbConnection conn = null;
PreparedStatement stmt = null;
ResultSet rs = null;
long totalSize = 0;
try {
conn = DbPool.getConnection();
StringBuilder sb = new StringBuilder();
sb.append("SELECT DISTINCT COALESCE(msgs.parent_id, msgs.msg_id) AS item_id," + " msgs.data_source_id AS data_source," + " COALESCE(convs.latest_date, msgs.mdate) AS newest_msg_date," + " COALESCE(convs.num_msgs, 1) AS num_msgs," + " COALESCE(convs.conv_size, msgs.msize) AS size");
sb.append(" FROM ");
sb.append("(SELECT di.data_source_id AS data_source_id, " + " mi.id AS msg_id," + " mi.parent_id AS parent_id," + " mi.size AS msize," + " mi.date AS mdate FROM ");
sb.append(getTableName(mbox)).append(" di ");
sb.append(" INNER JOIN ");
sb.append(DbMailItem.getMailItemTableName(mbox)).append(" mi ");
sb.append(" ON di.mailbox_id = mi.mailbox_id AND di.item_id = mi.id");
sb.append(" WHERE di.mailbox_id = ? AND mi.type = ? AND ");
sb.append(DbUtil.whereIn("di.data_source_id", dataSources.size()));
sb.append(") AS msgs");
sb.append(" LEFT JOIN ");
sb.append("(SELECT parent_id, max(date) AS latest_date, count(date) AS num_msgs, sum(size) AS conv_size");
sb.append(" FROM ").append(DbMailItem.getMailItemTableName(mbox));
sb.append(" WHERE mailbox_id = ? AND type = ? GROUP BY parent_id) AS convs");
sb.append(" ON msgs.parent_id = convs.parent_id");
if (startDate > 0L) {
sb.append(" WHERE COALESCE(convs.latest_date, msgs.mdate) > ?");
}
sb.append(" ORDER BY COALESCE(convs.latest_date, msgs.mdate) ASC");
stmt = conn.prepareStatement(sb.toString());
int pos = 1;
pos = DbMailItem.setMailboxId(stmt, mbox, pos);
stmt.setByte(pos++, MailItem.Type.MESSAGE.toByte());
for (DataSource ds : dataSources) {
stmt.setString(pos++, ds.getId());
}
pos = DbMailItem.setMailboxId(stmt, mbox, pos);
stmt.setByte(pos++, MailItem.Type.MESSAGE.toByte());
if (startDate > 0L) {
stmt.setLong(pos++, startDate);
}
rs = stmt.executeQuery();
List<PurgeableConv> convs = new LinkedList<PurgeableConv>();
while (rs.next() && totalSize < targetSize) {
long convSize = rs.getLong("size");
int itemId = rs.getInt("item_id");
int numMsgs = rs.getInt("num_msgs");
long convDate = rs.getLong("newest_msg_date");
String dataSourceId = rs.getString("data_source");
convs.add(new PurgeableConv(itemId, convSize, convDate, dataSourceId, numMsgs));
totalSize += convSize;
}
rs.close();
stmt.close();
return convs;
} catch (SQLException e) {
throw ServiceException.FAILURE("Unable to get oldest conversations for data sources", e);
} finally {
DbPool.closeResults(rs);
DbPool.closeStatement(stmt);
DbPool.quietClose(conn);
}
}
use of com.zimbra.cs.account.DataSource in project zm-mailbox by Zimbra.
the class DeleteDataSource method handle.
@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException, SoapFaultException {
ZimbraSoapContext zsc = getZimbraSoapContext(context);
Provisioning prov = Provisioning.getInstance();
Account account = getRequestedAccount(zsc);
if (!canModifyOptions(zsc, account))
throw ServiceException.PERM_DENIED("can not modify options");
Mailbox mbox = getRequestedMailbox(zsc);
for (Element eDsrc : request.listElements()) {
DataSource dsrc = null;
String name, id = eDsrc.getAttribute(MailConstants.A_ID, null);
if (id != null)
dsrc = prov.get(account, Key.DataSourceBy.id, id);
else if ((name = eDsrc.getAttribute(MailConstants.A_NAME, null)) != null)
dsrc = prov.get(account, Key.DataSourceBy.name, name);
else
throw ServiceException.INVALID_REQUEST("must specify either 'id' or 'name'", null);
// note that we're not checking the element name against the actual data source's type
if (dsrc == null)
continue;
String dataSourceId = dsrc.getId();
DataSourceType dstype = dsrc.getType();
prov.deleteDataSource(account, dataSourceId);
DbDataSource.deletePurgedDataForDataSource(mbox, dataSourceId);
if (dstype == DataSourceType.pop3)
DbPop3Message.deleteUids(mbox, dataSourceId);
else if (dstype == DataSourceType.imap) {
DbImapFolder.deleteImapData(mbox, dataSourceId);
DataSourceListner.deleteDataSource(account, dsrc);
}
DbDataSource.deleteAllMappings(dsrc);
DataSourceManager.cancelSchedule(account, dataSourceId);
}
Element response = zsc.createElement(MailConstants.DELETE_DATA_SOURCE_RESPONSE);
return response;
}
Aggregations