List of usage examples for java.text DateFormat MEDIUM
int MEDIUM
To view the source code for java.text DateFormat MEDIUM.
Click Source Link
From source file:org.etudes.mneme.impl.AttachmentServiceImpl.java
/** * Returns date in specified format//from w w w . j av a 2 s .c o m * @param date Date object * @return Date in specified format */ String formatDate(Date date) { if (date == null) return null; Locale userLocale = DateHelper.getPreferredLocale(null); TimeZone userZone = DateHelper.getPreferredTimeZone(null); DateFormat format = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM, userLocale); format.setTimeZone(userZone); return removeSeconds(format.format(date)); }
From source file:org.hoteia.qalingo.core.web.mvc.factory.ViewBeanFactory.java
/** * @throws Exception/*from w ww . j ava2 s . co m*/ * */ public UserViewBean buildViewBeanUser(final RequestData requestData, final User user) throws Exception { final HttpServletRequest request = requestData.getRequest(); final UserViewBean userViewBean = new UserViewBean(); if (user.getId() != null) { userViewBean.setId(user.getId().toString()); } userViewBean.setActive(user.isActive()); userViewBean.setValidated(user.isValidated()); userViewBean.setCode(user.getCode()); userViewBean.setLogin(user.getLogin()); userViewBean.setFirstname(user.getFirstname()); userViewBean.setLastname(user.getLastname()); userViewBean.setEmail(user.getEmail()); userViewBean.setPassword(user.getPassword()); if (user.getBirthday() != null) { userViewBean.setBirthday(buildCommonFormatDate(requestData, user.getBirthday())); } userViewBean.setAddress1(user.getAddress1()); userViewBean.setAddress2(user.getAddress2()); userViewBean.setAddressAdditionalInformation(user.getAddressAdditionalInformation()); userViewBean.setPostalCode(user.getPostalCode()); userViewBean.setCity(user.getCity()); userViewBean.setStateCode(user.getStateCode()); userViewBean.setAreaCode(user.getAreaCode()); userViewBean.setCountryCode(user.getCountryCode()); userViewBean.setPhone(user.getPhone()); userViewBean.setMobile(user.getMobile()); userViewBean.setEmail(user.getEmail()); if (user.getDateCreate() != null) { userViewBean.setDateCreate(buildCommonFormatDate(requestData, user.getDateCreate())); } if (user.getDateUpdate() != null) { userViewBean.setDateUpdate(buildCommonFormatDate(requestData, user.getDateUpdate())); } if (user.getGroups() != null && Hibernate.isInitialized(user.getGroups())) { final Set<UserGroup> groups = user.getGroups(); for (UserGroup group : groups) { String keyUserGroup = group.getCode(); String valueUserGroup = group.getName(); userViewBean.getGroups().put(keyUserGroup, valueUserGroup); if (group.getRoles() != null && Hibernate.isInitialized(group.getRoles())) { final Set<UserRole> roles = group.getRoles(); for (UserRole role : roles) { String keyUserRole = role.getCode(); String valueUserRole = role.getName(); userViewBean.getRoles().put(keyUserRole, valueUserRole); if (role.getPermissions() != null && Hibernate.isInitialized(role.getPermissions())) { final Set<UserPermission> permissions = role.getPermissions(); for (UserPermission permission : permissions) { String keyUserPermission = permission.getCode(); String valueUserPermission = permission.getName(); userViewBean.getPermissions().put(keyUserPermission, valueUserPermission); } } } } } } if (user.getConnectionLogs() != null && Hibernate.isInitialized(user.getConnectionLogs())) { final Set<UserConnectionLog> connectionLogs = user.getConnectionLogs(); for (UserConnectionLog connectionLog : connectionLogs) { UserConnectionLogValueBean connectionLogValueBean = new UserConnectionLogValueBean(); DateFormat dateFormat = requestUtil.getCommonFormatDate(requestData, DateFormat.MEDIUM, DateFormat.MEDIUM); connectionLogValueBean.setDate(dateFormat.format(connectionLog.getLoginDate())); connectionLogValueBean.setHost(Constants.NOT_AVAILABLE); if (StringUtils.isNotEmpty(connectionLog.getHost())) { connectionLogValueBean.setHost(connectionLog.getHost()); } connectionLogValueBean.setPublicAddress(Constants.NOT_AVAILABLE); if (StringUtils.isNotEmpty(connectionLog.getPublicAddress())) { connectionLogValueBean.setPublicAddress(connectionLog.getPublicAddress()); } connectionLogValueBean.setPrivateAddress(Constants.NOT_AVAILABLE); if (StringUtils.isNotEmpty(connectionLog.getPrivateAddress())) { connectionLogValueBean.setPublicAddress(connectionLog.getPrivateAddress()); } userViewBean.getUserConnectionLogs().add(connectionLogValueBean); } } final List<String> excludedPatterns = new ArrayList<String>(); excludedPatterns.add("form"); userViewBean.setBackUrl(requestUtil.getLastRequestUrl(request, excludedPatterns)); return userViewBean; }
From source file:org.hoteia.qalingo.core.web.mvc.factory.ViewBeanFactory.java
public CmsContentViewBean buildViewBeanCmsContent(final RequestData requestData, final CmsContent cmsContent) throws Exception { CmsContentViewBean cmsContentViewBean = new CmsContentViewBean(); if (cmsContent != null) { cmsContentViewBean.setId(cmsContent.getId().toString()); cmsContentViewBean.setCode(cmsContent.getCode()); cmsContentViewBean.setApp(cmsContent.getApp()); cmsContentViewBean.setType(cmsContent.getType()); cmsContentViewBean.setTitle(cmsContent.getTitle()); cmsContentViewBean.setLinkTitle(cmsContent.getLinkTitle()); cmsContentViewBean.setSeoSegment(cmsContent.getSeoSegment()); cmsContentViewBean.setSeoKey(cmsContent.getSeoKey()); cmsContentViewBean.setSummary(cmsContent.getSummary()); cmsContentViewBean.setMaster(cmsContent.isMaster()); cmsContentViewBean.setActive(cmsContent.isActive()); // USER/*from w w w . j a v a 2 s . co m*/ if (Hibernate.isInitialized(cmsContent.getUser()) && cmsContent.getUser() != null) { cmsContentViewBean.setUser(buildViewBeanUser(requestData, cmsContent.getUser())); } // MARKET AREA if (Hibernate.isInitialized(cmsContent.getMarketArea()) && cmsContent.getMarketArea() != null) { cmsContentViewBean.setMarketArea(buildViewBeanMarketArea(requestData, cmsContent.getMarketArea())); } // LOCALIZATION if (Hibernate.isInitialized(cmsContent.getLocalization()) && cmsContent.getLocalization() != null) { cmsContentViewBean .setLocalization(buildViewBeanLocalization(requestData, cmsContent.getLocalization())); } // MASTER CMS CONTENT if (Hibernate.isInitialized(cmsContent.getMasterCmsContent()) && cmsContent.getMasterCmsContent() != null) { cmsContentViewBean.setMasterCmsContent( buildViewBeanCmsContent(requestData, cmsContent.getMasterCmsContent())); } // BLOCK if (Hibernate.isInitialized(cmsContent.getBlocks()) && cmsContent.getBlocks() != null) { for (Iterator<CmsContentBlock> iterator = cmsContent.getSortedCmsContentBlocks() .iterator(); iterator.hasNext();) { CmsContentBlock block = (CmsContentBlock) iterator.next(); CmsContentBlockViewBean blockViewBean = buildViewBeanCmsContentBlock(requestData, cmsContent, block); cmsContentViewBean.getBlocks().add(blockViewBean); } } // PRODUCT BRAND if (Hibernate.isInitialized(cmsContent.getProductBrands()) && cmsContent.getProductBrands() != null) { List<SpecificFetchMode> productBrandFetchplans = new ArrayList<SpecificFetchMode>(); productBrandFetchplans.add(new SpecificFetchMode(ProductBrand_.attributes.getName())); productBrandFetchplans.add(new SpecificFetchMode(ProductBrand_.assets.getName())); for (Iterator<ProductBrand> iterator = cmsContent.getProductBrands().iterator(); iterator .hasNext();) { ProductBrand productBrand = (ProductBrand) iterator.next(); ProductBrand reloadedProductBrand = productService.getProductBrandById(productBrand.getId(), new FetchPlan(productBrandFetchplans)); ProductBrandViewBean productBrandViewBean = buildViewBeanProductBrand(requestData, reloadedProductBrand); cmsContentViewBean.getProductBrands().add(productBrandViewBean); } } // ASSETS if (Hibernate.isInitialized(cmsContent.getAssets()) && cmsContent.getAssets() != null) { for (Iterator<CmsContentAsset> iterator = cmsContent.getSortedAssets().iterator(); iterator .hasNext();) { CmsContentAsset asset = (CmsContentAsset) iterator.next(); AssetViewBean assetViewBean = buildViewBeanCmsContentAsset(requestData, asset); final String path = engineSettingService.getCmsContentImageWebPath(cmsContent, asset); assetViewBean.setRelativeWebPath(path); assetViewBean.setAbsoluteWebPath(urlService.buildAbsoluteUrl(requestData, path)); if (cmsContent.getAssets().size() == 1) { assetViewBean.setType("default"); } cmsContentViewBean.getAssets().add(assetViewBean); } } Date datePublish = cmsContent.getDatePublish(); if (datePublish == null) { datePublish = cmsContent.getDateCreate(); } DateFormat dateFormat = requestUtil.getCommonFormatDate(requestData, DateFormat.MEDIUM, null); if (datePublish != null) { cmsContentViewBean.setDatePublish(dateFormat.format(datePublish)); } SimpleDateFormat formatDay = new SimpleDateFormat("dd"); cmsContentViewBean.setDateCreateDay(formatDay.format(datePublish)); SimpleDateFormat formatMonthYear = new SimpleDateFormat("MMM yyyy"); cmsContentViewBean.setDateCreateMonthYear(formatMonthYear.format(datePublish)); if (cmsContent.getDateCreate() != null) { cmsContentViewBean.setDateCreate(dateFormat.format(cmsContent.getDateCreate())); } if (cmsContent.getDateUpdate() != null) { cmsContentViewBean.setDateUpdate(dateFormat.format(cmsContent.getDateUpdate())); } cmsContentViewBean.setEditUrl( backofficeUrlService.generateUrl(BoUrls.MANAGE_EDIT_ARTICLE, requestData, cmsContent)); cmsContentViewBean .setDetailsUrl(urlService.generateUrl(FoUrls.ARTICLE_CMS_CONTENT, requestData, cmsContent)); } return cmsContentViewBean; }
From source file:org.hoteia.qalingo.core.web.mvc.factory.ViewBeanFactory.java
public CmsContentBlockViewBean buildViewBeanCmsContentBlock(final RequestData requestData, final AbstractCmsEntity cmsEntity, final CmsContentBlock block) throws Exception { final MarketArea marketArea = requestData.getMarketArea(); final CmsContentBlockViewBean blockViewBean = new CmsContentBlockViewBean(); blockViewBean.setId(block.getId().toString()); blockViewBean.setType(block.getType()); blockViewBean.setOrdering(block.getOrdering()); blockViewBean.setActive(block.isActive()); if (Hibernate.isInitialized(block.getMarketArea()) && block.getMarketArea() != null) { blockViewBean.setMarketArea(buildViewBeanMarketArea(requestData, block.getMarketArea())); }/*from www. j av a 2 s . co m*/ blockViewBean.setTitle(block.getTitle()); blockViewBean.setText(block.getText()); blockViewBean.setParams(block.getParams()); // CMS CONTENT PARENT if (Hibernate.isInitialized(block.getCmsContent()) && block.getCmsContent() != null) { CmsContent clonedCmsContent = new CmsContent(); BeanUtils.copyProperties(block.getCmsContent(), clonedCmsContent); clonedCmsContent.setBlocks(null); CmsContentViewBean parentViewBean = buildViewBeanCmsContent(requestData, clonedCmsContent); blockViewBean.setCmsContent(parentViewBean); } // LINK if (Hibernate.isInitialized(block.getLink()) && block.getLink() != null) { CmsContentLinkViewBean linkViewBean = buildViewBeanCmsContentLink(requestData, block.getLink()); if (StringUtils.isEmpty(linkViewBean.getName())) { linkViewBean.setName(block.getTitle()); } blockViewBean.setLink(linkViewBean); } // ASSETS if (block.getAssets() != null && Hibernate.isInitialized(block.getAssets()) && block.getAssets().size() > 0) { for (Iterator<CmsContentAsset> iteratorCmsContentAsset = block.getSortedAssets() .iterator(); iteratorCmsContentAsset.hasNext();) { CmsContentAsset asset = (CmsContentAsset) iteratorCmsContentAsset.next(); AssetViewBean assetViewBean = buildViewBeanCmsContentAsset(requestData, asset); final String path = engineSettingService.getCmsContentImageWebPath(cmsEntity, block, asset); assetViewBean.setRelativeWebPath(path); assetViewBean.setAbsoluteWebPath(urlService.buildAbsoluteUrl(requestData, path)); blockViewBean.getAssets().add(assetViewBean); } } // BLOCK if (Hibernate.isInitialized(block.getCmsContentBlock()) && block.getCmsContentBlock() != null) { CmsContentBlock clonedCmsContentBlock = new CmsContentBlock(); BeanUtils.copyProperties(block.getCmsContentBlock(), clonedCmsContentBlock); clonedCmsContentBlock.setBlocks(null); CmsContentBlockViewBean parentBlockViewBean = buildViewBeanCmsContentBlock(requestData, cmsEntity, clonedCmsContentBlock); blockViewBean.setCmsContentBlock(parentBlockViewBean); } if (Hibernate.isInitialized(block.getBlocks()) && block.getBlocks() != null) { for (Iterator<CmsContentBlock> iterator = block.getSortedCmsContentBlocks().iterator(); iterator .hasNext();) { CmsContentBlock subBlock = (CmsContentBlock) iterator.next(); CmsContentBlockViewBean subBlockViewBean = buildViewBeanCmsContentBlock(requestData, cmsEntity, subBlock); blockViewBean.getBlocks().add(subBlockViewBean); } } if (StringUtils.isNotEmpty(block.getType())) { if (block.getType().contains("PRODUCT_SELECTION_SMALL") || block.getType().contains("PRODUCT_SELECTION_MEDIUM")) { String[] productCodes = block.getParams().split(";"); List<SpecificFetchMode> fetchplansProductMarketing = new ArrayList<SpecificFetchMode>(); fetchplansProductMarketing .add(new SpecificFetchMode(ProductMarketing_.productMarketingType.getName())); fetchplansProductMarketing.add(new SpecificFetchMode(ProductMarketing_.productBrand.getName())); fetchplansProductMarketing.add(new SpecificFetchMode(ProductMarketing_.attributes.getName())); fetchplansProductMarketing.add(new SpecificFetchMode(ProductMarketing_.assets.getName())); fetchplansProductMarketing.add(new SpecificFetchMode(ProductMarketing_.productSkus.getName())); fetchplansProductMarketing.add(new SpecificFetchMode( ProductMarketing_.productSkus.getName() + "." + ProductSku_.assets.getName())); fetchplansProductMarketing.add(new SpecificFetchMode(ProductMarketing_.productSkus.getName() + "." + ProductSku_.catalogCategoryVirtualProductSkuRels.getName())); fetchplansProductMarketing.add(new SpecificFetchMode(ProductMarketing_.productSkus.getName() + "." + ProductSku_.catalogCategoryVirtualProductSkuRels.getName() + "." + CatalogCategoryVirtualProductSkuRel_.pk.getName())); fetchplansProductMarketing.add(new SpecificFetchMode(ProductMarketing_.productSkus.getName() + "." + ProductSku_.catalogCategoryVirtualProductSkuRels.getName() + "." + CatalogCategoryVirtualProductSkuRel_.pk.getName() + "." + CatalogCategoryVirtualProductSkuPk_.catalogCategoryVirtual.getName())); List<SpecificFetchMode> fetchplansProductSku = new ArrayList<SpecificFetchMode>(); fetchplansProductSku.add(new SpecificFetchMode(ProductSku_.productMarketing.getName())); fetchplansProductSku.add(new SpecificFetchMode( ProductSku_.productMarketing.getName() + "." + ProductMarketing_.productBrand.getName())); fetchplansProductSku.add(new SpecificFetchMode(ProductSku_.attributes.getName())); fetchplansProductSku.add(new SpecificFetchMode(ProductSku_.assets.getName())); fetchplansProductSku .add(new SpecificFetchMode(ProductSku_.catalogCategoryVirtualProductSkuRels.getName())); fetchplansProductSku .add(new SpecificFetchMode(ProductSku_.catalogCategoryVirtualProductSkuRels.getName() + "." + CatalogCategoryVirtualProductSkuRel_.pk.getName())); fetchplansProductSku .add(new SpecificFetchMode(ProductSku_.catalogCategoryVirtualProductSkuRels.getName() + "." + CatalogCategoryVirtualProductSkuRel_.pk.getName() + "." + CatalogCategoryVirtualProductSkuPk_.catalogCategoryVirtual.getName())); for (int i = 0; i < productCodes.length; i++) { String productMarketingCode = productCodes[i]; ProductSku productSku = productService.getProductSkuByCode(productMarketingCode, new FetchPlan(fetchplansProductSku)); ProductMarketing productMarketing = null; ProductMarketingViewBean productMarketingViewBean = null; if (productSku != null) { productMarketing = productService.getProductMarketingByCode( productSku.getProductMarketing().getCode(), new FetchPlan(fetchplansProductMarketing)); CatalogCategoryVirtual catalogCategoryVirtual = productSku .getDefaultCatalogCategoryVirtual(marketArea.getCatalog()); ProductSkuViewBean productSkuViewBean = buildViewBeanProductSku(requestData, productSku); productMarketingViewBean = buildViewBeanProductMarketing(requestData, catalogCategoryVirtual, productMarketing, productSku); // HACK : USE SKU AS DEFAULT ASSET productMarketingViewBean.getDefaultAsset() .setAbsoluteWebPath(productSkuViewBean.getDefaultAsset().getAbsoluteWebPath()); } else { productMarketing = productService.getProductMarketingByCode(productMarketingCode, new FetchPlan(fetchplansProductMarketing)); productMarketingViewBean = buildViewBeanProductMarketing(requestData, productMarketing); } if (productMarketing != null) { if (block.getType().contains("PRODUCT_SELECTION_SMALL")) { if (productMarketingViewBean != null && StringUtils.isNotEmpty(productMarketingViewBean.getDetailsUrl())) { blockViewBean.getProductMarketings().add(productMarketingViewBean); } else { // HACK : CAT EMPTY productSku = productMarketing.getDefaultProductSku(); if (productSku != null) { CatalogCategoryVirtual catalogCategory = catalogCategoryService .getVirtualCatalogCategoryByCode("GLASSES", marketArea.getCatalog().getCode()); if (catalogCategory != null) { productMarketingViewBean.setDetailsUrl( urlService.generateUrl(FoUrls.PRODUCT_DETAILS, requestData, catalogCategory, productMarketing, productSku)); } if (productMarketingViewBean != null && StringUtils.isNotEmpty(productMarketingViewBean.getDetailsUrl())) { blockViewBean.getProductMarketings().add(productMarketingViewBean); } } } } if (block.getType().contains("PRODUCT_SELECTION_MEDIUM")) { if (productMarketingViewBean != null && StringUtils.isNotEmpty(productMarketingViewBean.getDetailsUrl())) { blockViewBean.getProductMarketings().add(productMarketingViewBean); } else { // HACK : CAT EMPTY productSku = productMarketing.getDefaultProductSku(); if (productSku != null) { CatalogCategoryVirtual catalogCategory = catalogCategoryService .getVirtualCatalogCategoryByCode("GLASSES", marketArea.getCatalog().getCode()); if (catalogCategory != null) { productMarketingViewBean.setDetailsUrl( urlService.generateUrl(FoUrls.PRODUCT_DETAILS, requestData, catalogCategory, productMarketing, productSku)); } if (productMarketingViewBean != null && StringUtils.isNotEmpty(productMarketingViewBean.getDetailsUrl())) { blockViewBean.getProductMarketings().add(productMarketingViewBean); } } } } } } if (block.getType().contains("STORE_SELECTION_MEDIUM") || block.getType().contains("STORE_SELECTION_SMALL")) { GeolocData geolocData = requestData.getGeolocData(); List<SpecificFetchMode> storeFetchPlans = new ArrayList<SpecificFetchMode>(); storeFetchPlans.add(new SpecificFetchMode(Store_.attributes.getName())); storeFetchPlans.add(new SpecificFetchMode(Store_.assets.getName())); int maxStoreList = 5; List<GeolocatedStore> storeRandom = null; if (geolocData != null) { storeRandom = new ArrayList<GeolocatedStore>(); int distance = 20; storeRandom = retailerService.findRandomB2CStores(marketArea, geolocData, maxStoreList, distance); int escape = 10; int retray = 0; while (storeRandom == null || (storeRandom != null && storeRandom.size() < maxStoreList)) { if (retray > escape) { break; } storeRandom = retailerService.findRandomB2CStores(marketArea, geolocData, maxStoreList, distance); distance = distance + 15; retray++; } } List<Store> stores = new ArrayList<Store>(); if (storeRandom != null) { for (Iterator<GeolocatedStore> iterator = storeRandom.iterator(); iterator.hasNext();) { GeolocatedStore geolocatedStore = (GeolocatedStore) iterator.next(); Store store = retailerService.getStoreById(geolocatedStore.getId(), new FetchPlan(storeFetchPlans)); stores.add(store); } } else { // DEFAULT LIST : LIKE BOT WITHOUT GEOLOC List<String> types = new ArrayList<String>(); types.add("OPTICIAN"); stores = retailerService.findB2CStoresByType(types, maxStoreList, new FetchPlan(storeFetchPlans)); } for (Store store : stores) { Store reloadedStore = retailerService.getStoreByCode(store.getCode(), new FetchPlan(storeFetchPlans)); if (store != null) { if (block.getType().contains("STORE_SELECTION_MEDIUM") && blockViewBean.getStores().size() < 5) { StoreViewBean storeViewBean = buildViewBeanStore(requestData, reloadedStore); if (storeViewBean != null && StringUtils.isNotEmpty(storeViewBean.getDetailsUrl())) { blockViewBean.getStores().add(storeViewBean); } } if (block.getType().contains("STORE_SELECTION_SMALL") && blockViewBean.getStores().size() < 10) { StoreViewBean storeViewBean = buildViewBeanStore(requestData, reloadedStore); if (storeViewBean != null && StringUtils.isNotEmpty(storeViewBean.getDetailsUrl())) { blockViewBean.getStores().add(storeViewBean); } } } } } } DateFormat dateFormat = requestUtil.getCommonFormatDate(requestData, DateFormat.MEDIUM, null); if (block.getDateCreate() != null) { blockViewBean.setDateCreate(dateFormat.format(block.getDateCreate())); } if (block.getDateUpdate() != null) { blockViewBean.setDateUpdate(dateFormat.format(block.getDateUpdate())); } } return blockViewBean; }
From source file:org.hoteia.qalingo.core.web.mvc.factory.ViewBeanFactory.java
protected String buildMediumFormatDate(RequestData requestData, Date date) throws Exception { DateFormat dateFormat = requestUtil.getCommonFormatDate(requestData, DateFormat.MEDIUM, DateFormat.MEDIUM); return dateFormat.format(date); }
From source file:net.spfbl.http.ServerHTTP.java
private static String getControlPanel(Locale locale, Query query, long time) { DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM, locale); GregorianCalendar calendar = new GregorianCalendar(); calendar.setTimeInMillis(time);//ww w.j av a2 s . co m StringBuilder builder = new StringBuilder(); // builder.append("<!DOCTYPE html>\n"); builder.append("<html lang=\""); builder.append(locale.getLanguage()); builder.append("\">\n"); builder.append(" <head>\n"); builder.append(" <meta charset=\"UTF-8\">\n"); if (locale.getLanguage().toLowerCase().equals("pt")) { builder.append(" <title>Painel de controle do SPFBL</title>\n"); } else { builder.append(" <title>SPFBL control panel</title>\n"); } // Styled page. builder.append(" <style type=\"text/css\">\n"); builder.append(" body {"); builder.append(" background: #b4b9d2;\n"); builder.append(" }\n"); builder.append(" .button {\n"); builder.append(" background-color: #4CAF50;\n"); builder.append(" border: none;\n"); builder.append(" color: white;\n"); builder.append(" padding: 16px 32px;\n"); builder.append(" text-align: center;\n"); builder.append(" text-decoration: none;\n"); builder.append(" display: inline-block;\n"); builder.append(" font-size: 16px;\n"); builder.append(" margin: 4px 2px;\n"); builder.append(" -webkit-transition-duration: 0.4s;\n"); builder.append(" transition-duration: 0.4s;\n"); builder.append(" cursor: pointer;\n"); builder.append(" }\n"); builder.append(" .white {\n"); builder.append(" background-color: white; \n"); builder.append(" color: black; \n"); builder.append(" border: 2px solid #4CAF50;\n"); builder.append(" font-weight: bold;\n"); builder.append(" }\n"); builder.append(" .white:hover {\n"); builder.append(" background-color: #4CAF50;\n"); builder.append(" color: white;\n"); builder.append(" }\n"); builder.append(" .block {\n"); builder.append(" background-color: white; \n"); builder.append(" color: black; \n"); builder.append(" border: 2px solid #f44336;\n"); builder.append(" font-weight: bold;\n"); builder.append(" }\n"); builder.append(" .block:hover {\n"); builder.append(" background-color: #f44336;\n"); builder.append(" color: white;\n"); builder.append(" }\n"); builder.append(" .recipient {\n"); builder.append(" background-color: white; \n"); builder.append(" color: black; \n"); builder.append(" border: 2px solid #555555;\n"); builder.append(" font-weight: bold;\n"); builder.append(" }\n"); builder.append(" .recipient:hover {\n"); builder.append(" background-color: #555555;\n"); builder.append(" color: white;\n"); builder.append(" }\n"); builder.append(" </style>\n"); builder.append(" </head>\n"); // Body. builder.append(" <body>\n"); if (locale.getLanguage().toLowerCase().equals("pt")) { builder.append(" <b>Recepo:</b> "); } else { builder.append(" <b>Reception:</b> "); } builder.append(dateFormat.format(calendar.getTime())); builder.append("<br>\n"); String sender = query.getSenderSimplified(false, false); if (sender == null) { if (locale.getLanguage().toLowerCase().equals("pt")) { builder.append(" <b>Remetente:</b> MAILER-DAEMON"); } else { builder.append(" <b>Sender:</b> MAILER-DAEMON"); } } else if (query.getQualifierName().equals("PASS")) { if (locale.getLanguage().toLowerCase().equals("pt")) { builder.append(" <b>Remetente autntico:</b> "); } else { builder.append(" <b>Genuine sender:</b> "); } builder.append(sender); } else if (query.getQualifierName().equals("FAIL")) { if (locale.getLanguage().toLowerCase().equals("pt")) { builder.append(" <b>Remetente falso:</b> "); } else { builder.append(" <b>False sender:</b> "); } builder.append(sender); } else { if (locale.getLanguage().toLowerCase().equals("pt")) { builder.append(" <b>Remetente suspeito:</b> "); } else { builder.append(" <b>Suspect sender:</b> "); } builder.append(sender); } builder.append("<br>\n"); if (locale.getLanguage().toLowerCase().equals("pt")) { builder.append(" <b>Recebe por:</b> "); } else { builder.append(" <b>Receives for:</b> "); } String validator = query.getValidator(true); Situation situationWhite = query.getSenderWhiteSituation(); Situation situationBlock = query.getSenderBlockSituation(); try { TreeSet<String> mxDomainSet = query.getSenderMXDomainSet(); if (mxDomainSet.isEmpty()) { if (locale.getLanguage().toLowerCase().equals("pt")) { builder.append("nenhum sistema"); } else { builder.append("no system"); } } else { builder.append(mxDomainSet); } } catch (NameNotFoundException ex) { validator = null; situationWhite = query.getOriginWhiteSituation(); situationBlock = query.getOriginBlockSituation(); if (locale.getLanguage().toLowerCase().equals("pt")) { builder.append("domnio inexistente"); } else { builder.append("non-existent domain"); } } catch (NamingException ex) { if (locale.getLanguage().toLowerCase().equals("pt")) { builder.append("erro ao tentar consultar"); } else { builder.append("error when trying to query"); } } builder.append("<br>\n"); URL unsubscribe = query.getUnsubscribeURL(); if (unsubscribe == null) { builder.append(" <br>\n"); } else { if (locale.getLanguage().toLowerCase().equals("pt")) { builder.append(" <b>Cancelar inscrio:</b> "); } else { builder.append(" <b>List unsubscribe:</b> "); } builder.append("<a target=\"_blank\" href=\""); builder.append(unsubscribe); builder.append("\">"); builder.append(unsubscribe.getHost()); builder.append(unsubscribe.getPath()); builder.append("</a><br>\n"); } if (locale.getLanguage().toLowerCase().equals("pt")) { builder.append(" <b>Politica vigente:</b> "); } else { builder.append(" <b>Current policy:</b> "); } String recipient = query.getRecipient(); Long trapTime = query.getTrapTime(); boolean blocked = false; if (trapTime == null && situationWhite == Situation.SAME) { if (locale.getLanguage().toLowerCase().equals("pt")) { builder.append("entrega prioritria na mesma situao, exceto malware"); } else { builder.append("priority delivery of "); builder.append(query.getSenderSimplified(false, true)); builder.append(" in the same situation, except malware"); } } else if (trapTime == null && situationWhite == Situation.AUTHENTIC) { if (locale.getLanguage().toLowerCase().equals("pt")) { builder.append("entrega prioritria de "); builder.append(query.getSenderSimplified(false, true)); builder.append(" quando comprovadamente autntico, exceto malware"); } else { builder.append("priority delivery of "); builder.append(query.getSenderSimplified(false, true)); builder.append(" when proven authentic, except malware"); } if (query.isBlock()) { if (locale.getLanguage().toLowerCase().equals("pt")) { builder.append(", porm bloqueado para outras situaes"); } else { builder.append(", however blocked to other situations"); } } } else if (trapTime == null && situationWhite == Situation.ZONE) { if (locale.getLanguage().toLowerCase().equals("pt")) { builder.append("entrega prioritria de "); builder.append(query.getSenderSimplified(false, true)); builder.append(" quando disparado por "); } else { builder.append("priority delivery of "); builder.append(query.getSenderSimplified(false, true)); builder.append(" when shot by "); } builder.append(validator); if (query.isBlock()) { if (locale.getLanguage().toLowerCase().equals("pt")) { builder.append(", porm bloqueado para outras situaes"); } else { builder.append(", however blocked to other situations"); } } } else if (trapTime == null && situationWhite == Situation.IP) { if (locale.getLanguage().toLowerCase().equals("pt")) { builder.append("entrega prioritria de "); builder.append(query.getSenderSimplified(false, true)); builder.append(" when shot by IP "); } else { builder.append("priority delivery of "); builder.append(query.getSenderSimplified(false, true)); builder.append(" when coming from the IP "); } builder.append(validator); if (query.isBlock()) { if (locale.getLanguage().toLowerCase().equals("pt")) { builder.append(", porm bloqueado para outras situaes"); } else { builder.append(", however blocked to other situations"); } } } else if (trapTime == null && situationWhite == Situation.ORIGIN) { if (locale.getLanguage().toLowerCase().equals("pt")) { builder.append("entrega prioritria pela mesma origem"); } else { builder.append("priority delivery the same origin"); } } else if (situationBlock == Situation.DOMAIN) { blocked = true; String domain = query.getSenderSimplified(true, false); if (domain == null) { if (locale.getLanguage().toLowerCase().equals("pt")) { builder.append("bloquear na mesma situao"); } else { builder.append("block in the same situation"); } } else { if (locale.getLanguage().toLowerCase().equals("pt")) { builder.append("bloquear "); builder.append(domain); builder.append(" em qualquer situao"); } else { builder.append("block "); builder.append(domain); builder.append(" in any situation"); } } } else if (situationBlock == Situation.ALL) { blocked = true; String domain = query.getOriginDomain(false); if (domain == null) { if (locale.getLanguage().toLowerCase().equals("pt")) { builder.append("bloquear na mesma situao"); } else { builder.append("block in the same situation"); } } else { if (locale.getLanguage().toLowerCase().equals("pt")) { builder.append("bloquear "); builder.append(domain); builder.append(" em qualquer situao"); } else { builder.append("block "); builder.append(domain); builder.append(" in any situation"); } } } else if (situationBlock == Situation.SAME) { blocked = true; if (locale.getLanguage().toLowerCase().equals("pt")) { builder.append("bloquear na mesma situao"); } else { builder.append("block in the same situation"); } } else if ((situationBlock == Situation.ZONE || situationBlock == Situation.IP) && !query.getQualifierName().equals("PASS")) { blocked = true; if (locale.getLanguage().toLowerCase().equals("pt")) { builder.append("bloquear "); builder.append(query.getSenderDomain(false)); builder.append(" quando no for autntico"); } else { builder.append("block "); builder.append(query.getSenderDomain(false)); builder.append(" when not authentic"); } } else if (situationBlock == Situation.ORIGIN) { blocked = true; if (locale.getLanguage().toLowerCase().equals("pt")) { builder.append("bloquear quando disparado pela mesma origem"); } else { builder.append("block when shot by the same source"); } } else if (query.isFail()) { blocked = true; if (locale.getLanguage().toLowerCase().equals("pt")) { builder.append("rejeitar entrega por falsificao"); } else { builder.append("reject delivery of forgery"); } } else if (trapTime != null) { if (System.currentTimeMillis() > trapTime) { if (locale.getLanguage().toLowerCase().equals("pt")) { builder.append("descartar mensagem por armadilha"); } else { builder.append("discard message by spamtrap"); } } else { if (locale.getLanguage().toLowerCase().equals("pt")) { builder.append("rejeitar entrega por destinatrio inexistente"); } else { builder.append("reject delivery by inexistent recipient"); } } } else if (query.hasTokenRed() || query.hasClusterRed()) { if (locale.getLanguage().toLowerCase().equals("pt")) { builder.append("marcar como suspeita e entregar, sem considerar o contedo"); } else { builder.append("flag as suspected and deliver, regardless of content"); } } else if (query.isSoftfail() || query.hasYellow()) { if (locale.getLanguage().toLowerCase().equals("pt")) { builder.append("atrasar entrega na mesma situao, sem considerar o contedo"); } else { builder.append("delay delivery in the same situation, regardless of content"); } } else { if (locale.getLanguage().toLowerCase().equals("pt")) { builder.append("aceitar entrega na mesma situao, sem considerar o contedo"); } else { builder.append("accept delivery in the same situation, regardless of content"); } } builder.append(".<br>\n"); builder.append(" <form method=\"POST\">\n"); if (validator == null) { if (situationWhite != Situation.ORIGIN) { builder.append( " <button type=\"submit\" class=\"white\" name=\"POLICY\" value=\"WHITE_ORIGIN\">"); if (locale.getLanguage().toLowerCase().equals("pt")) { builder.append("Entrega prioritria quando for da mesma origem\n"); } else { builder.append("Priority delivery when the same origin\n"); } builder.append("</button>\n"); } if (situationWhite != Situation.NONE || situationBlock != Situation.ALL) { if (situationBlock != Situation.ORIGIN) { builder.append( " <button type=\"submit\" class=\"block\" name=\"POLICY\" value=\"BLOCK_ORIGIN\">"); if (locale.getLanguage().toLowerCase().equals("pt")) { builder.append("Bloquear se for da mesma origem"); } else { builder.append("Block if the same origin"); } builder.append("</button>\n"); } String domain = query.getOriginDomain(false); if (domain != null) { builder.append( " <button type=\"submit\" class=\"block\" name=\"POLICY\" value=\"BLOCK_ALL\">"); if (locale.getLanguage().toLowerCase().equals("pt")) { builder.append("Bloquear "); builder.append(domain); builder.append(" em qualquer situao"); } else { builder.append("Block "); builder.append(domain); builder.append(" in any situation"); } builder.append("</button>\n"); } } } else if (validator.equals("PASS")) { if (situationWhite != Situation.AUTHENTIC) { builder.append( " <button type=\"submit\" class=\"white\" name=\"POLICY\" value=\"WHITE_AUTHENTIC\">"); if (locale.getLanguage().toLowerCase().equals("pt")) { builder.append("Entrega prioritria quando comprovadamente autntico\n"); } else { builder.append("Priority delivery when proven authentic\n"); } builder.append("</button>\n"); } } else if (Subnet.isValidIP(validator)) { if (situationWhite != Situation.IP) { builder.append(" <button type=\"submit\" class=\"white\" name=\"POLICY\" value=\"WHITE_IP\">"); if (locale.getLanguage().toLowerCase().equals("pt")) { builder.append("Entrega prioritria quando disparado pelo IP "); } else { builder.append("Priority delivery when shot by IP "); } builder.append(validator); builder.append("</button>\n"); } if (situationBlock != Situation.IP && situationBlock != Situation.DOMAIN) { builder.append(" <button type=\"submit\" class=\"block\" name=\"POLICY\" value=\"BLOCK_IP\">"); if (locale.getLanguage().toLowerCase().equals("pt")) { builder.append("Bloquear "); builder.append(query.getSenderDomain(false)); builder.append(" quando no for autntico"); } else { builder.append("Block "); builder.append(query.getSenderDomain(false)); builder.append(" when not authentic"); } builder.append("</button>\n"); } } else if (Domain.isHostname(validator)) { if (situationWhite != Situation.ZONE) { builder.append( " <button type=\"submit\" class=\"white\" name=\"POLICY\" value=\"WHITE_ZONE\">"); if (locale.getLanguage().toLowerCase().equals("pt")) { builder.append("Entrega prioritria quando disparado por "); } else { builder.append("Priority delivery when shot by "); } builder.append(validator); builder.append("</button>\n"); } if (situationBlock != Situation.ZONE && situationBlock != Situation.DOMAIN) { builder.append( " <button type=\"submit\" class=\"block\" name=\"POLICY\" value=\"BLOCK_ZONE\">"); if (locale.getLanguage().toLowerCase().equals("pt")) { builder.append("Bloquear "); builder.append(query.getSenderDomain(false)); builder.append(" quando no for autntico"); } else { builder.append("Block "); builder.append(query.getSenderDomain(false)); builder.append(" when not authentic"); } builder.append("</button>\n"); } } if (situationBlock != Situation.DOMAIN && validator != null) { builder.append(" <button type=\"submit\" class=\"block\" name=\"POLICY\" value=\"BLOCK_DOMAIN\">"); if (locale.getLanguage().toLowerCase().equals("pt")) { builder.append("Bloquear "); builder.append(query.getSenderSimplified(true, false)); builder.append(" em qualquer situao"); } else { builder.append("Block "); builder.append(query.getSenderSimplified(true, false)); builder.append(" in any situation"); } builder.append("</button>\n"); } if (!blocked && recipient != null && trapTime != null && query.getUser().isPostmaster()) { builder.append( " <button type=\"submit\" class=\"recipient\" name=\"POLICY\" value=\"WHITE_RECIPIENT\">"); if (locale.getLanguage().toLowerCase().equals("pt")) { builder.append("Tornar "); builder.append(recipient); builder.append(" existente"); } else { builder.append("Make "); builder.append(recipient); builder.append(" existent"); } builder.append("</button>\n"); } builder.append(" </form>\n"); builder.append(" </body>\n"); builder.append("</html>\n"); return builder.toString(); }
From source file:com.sonicle.webtop.mail.Service.java
public void processListMessages(HttpServletRequest request, HttpServletResponse response, PrintWriter out) { CoreManager core = WT.getCoreManager(); UserProfile profile = environment.getProfile(); Locale locale = profile.getLocale(); java.util.Calendar cal = java.util.Calendar.getInstance(locale); MailAccount account = getAccount(request); String pfoldername = request.getParameter("folder"); //String psortfield = request.getParameter("sort"); //String psortdir = request.getParameter("dir"); String pstart = request.getParameter("start"); String plimit = request.getParameter("limit"); String ppage = request.getParameter("page"); String prefresh = request.getParameter("refresh"); String ptimestamp = request.getParameter("timestamp"); String pthreaded = request.getParameter("threaded"); String pthreadaction = request.getParameter("threadaction"); String pthreadactionuid = request.getParameter("threadactionuid"); QueryObj queryObj = null;//from w w w. j av a 2 s . c o m SearchTerm searchTerm = null; try { queryObj = ServletUtils.getObjectParameter(request, "query", new QueryObj(), QueryObj.class); } catch (ParameterException parameterException) { logger.error("Exception getting query obejct parameter", parameterException); } boolean refresh = (prefresh != null && prefresh.equals("true")); //boolean threaded=(pthreaded!=null && pthreaded.equals("1")); //String threadedSetting="list-threaded-"+pfoldername; //if (pthreaded==null || pthreaded.equals("2")) { // threaded=us.isMessageListThreaded(pfoldername); //} else { // us.setMessageListThreaded(pfoldername, threaded); //} //System.out.println("timestamp="+ptimestamp); long timestamp = Long.parseLong(ptimestamp); if (account.isSpecialFolder(pfoldername) || account.isSharedFolder(pfoldername)) { logger.debug("folder is special or shared, refresh forced"); refresh = true; } String group = us.getMessageListGroup(pfoldername); if (group == null) { group = ""; } String psortfield = "date"; String psortdir = "DESC"; try { boolean nogroup = group.equals(""); JsSort.List sortList = ServletUtils.getObjectParameter(request, "sort", null, JsSort.List.class); if (sortList == null) { if (nogroup) { String s = us.getMessageListSort(pfoldername); int ix = s.indexOf("|"); psortfield = s.substring(0, ix); psortdir = s.substring(ix + 1); } else { psortfield = "date"; psortdir = "DESC"; } } else { JsSort jsSort = sortList.get(0); psortfield = jsSort.property; psortdir = jsSort.direction; if (!nogroup && !psortfield.equals("date")) { group = ""; } us.setMessageListGroup(pfoldername, group); us.setMessageListSort(pfoldername, psortfield, psortdir); } } catch (Exception exc) { logger.error("Exception", exc); } SortGroupInfo sgi = getSortGroupInfo(psortfield, psortdir, group); //Save search requests int start = Integer.parseInt(pstart); int limit = Integer.parseInt(plimit); int page = 0; if (ppage != null) { page = Integer.parseInt(ppage); start = (page - 1) * limit; } /*int start = 0; int limit = mprofile.getNumMsgList(); if (ppage==null) { if (pstart != null) { start = Integer.parseInt(pstart); } if (plimit != null) { limit = Integer.parseInt(plimit); } } else { int page=Integer.parseInt(ppage); int nxpage=mprofile.getNumMsgList(); start=(page-1)*nxpage; limit=nxpage; }*/ String sout = "{\n"; Folder folder = null; boolean connected = false; try { connected = account.checkStoreConnected(); if (!connected) throw new Exception("Mail account authentication error"); int funread = 0; if (pfoldername == null) { folder = account.getDefaultFolder(); } else { folder = account.getFolder(pfoldername); } boolean issent = account.isSentFolder(folder.getFullName()); boolean isundersent = account.isUnderSentFolder(folder.getFullName()); boolean isdrafts = account.isDraftsFolder(folder.getFullName()); boolean isundershared = account.isUnderSharedFolder(pfoldername); if (!issent) { String names[] = folder.getFullName().split("\\" + account.getFolderSeparator()); for (String pname : names) { if (account.isSentFolder(pname)) { issent = true; break; } } } String ctn = Thread.currentThread().getName(); String key = folder.getFullName(); if (!pfoldername.equals("/")) { FolderCache mcache = account.getFolderCache(key); if (mcache.toBeRefreshed()) refresh = true; //Message msgs[]=mcache.getMessages(ppattern,psearchfield,sortby,ascending,refresh); if (psortfield != null && psortdir != null) { key += "|" + psortdir + "|" + psortfield; } searchTerm = ImapQuery.toSearchTerm(this.allFlagStrings, this.atags, queryObj, profile.getTimeZone()); boolean hasAttachment = queryObj.conditions.stream() .anyMatch(condition -> condition.value.equals("attachment")); if (queryObj != null) refresh = true; MessagesInfo messagesInfo = listMessages(mcache, key, refresh, sgi, timestamp, searchTerm, hasAttachment); Message xmsgs[] = messagesInfo.messages; if (pthreadaction != null && pthreadaction.trim().length() > 0) { long actuid = Long.parseLong(pthreadactionuid); mcache.setThreadOpen(actuid, pthreadaction.equals("open")); } //if threaded, look for the start considering roots and opened children if (xmsgs != null && sgi.threaded && page > 1) { int i = 0, ni = 0, np = 1; long tId = 0; while (np < page && ni < xmsgs.length) { SonicleIMAPMessage xm = (SonicleIMAPMessage) xmsgs[ni]; ++ni; if (xm.isExpunged()) continue; long nuid = mcache.getUID(xm); int tIndent = xm.getThreadIndent(); if (tIndent == 0) tId = nuid; else { if (!mcache.isThreadOpen(tId)) continue; } ++i; if ((i % limit) == 0) ++np; } if (np == page) { start = ni; //System.out.println("page "+np+" start is "+start); } } int max = start + limit; if (xmsgs != null && max > xmsgs.length) max = xmsgs.length; ArrayList<Long> autoeditList = new ArrayList<Long>(); if (xmsgs != null) { int total = 0; int expunged = 0; //calculate expunged //for(Message xmsg: xmsgs) { // if (xmsg.isExpunged()) ++expunged; //} sout += "messages: [\n"; /* if (ppattern==null && !isSpecialFolder(mcache.getFolderName())) { //mcache.fetch(msgs,FolderCache.flagsFP,0,start); for(int i=0;i<start;++i) { try { if (!msgs[i].isSet(Flags.Flag.SEEN)) funread++; } catch(Exception exc) { } } }*/ total = sgi.threaded ? mcache.getThreadedCount() : xmsgs.length; if (start < max) { Folder fsent = account.getFolder(account.getFolderSent()); boolean openedsent = false; //Fetch others for these messages mcache.fetch(xmsgs, (isdrafts ? draftsFP : messagesInfo.isPEC() ? pecFP : FP), start, max); long tId = 0; for (int i = 0, ni = 0; i < limit; ++ni, ++i) { int ix = start + i; int nx = start + ni; if (nx >= xmsgs.length) break; if (ix >= max) break; SonicleIMAPMessage xm = (SonicleIMAPMessage) xmsgs[nx]; if (xm.isExpunged()) { --i; continue; } /*if (messagesInfo.checkSkipPEC(xm)) { --i; --total; continue; }*/ /*String ids[]=null; try { ids=xm.getHeader("Message-ID"); } catch(MessagingException exc) { --i; continue; } if (ids==null || ids.length==0) { --i; continue; } String idmessage=ids[0];*/ long nuid = mcache.getUID(xm); int tIndent = xm.getThreadIndent(); if (tIndent == 0) tId = nuid; else if (sgi.threaded) { if (!mcache.isThreadOpen(tId)) { --i; continue; } } boolean tChildren = false; int tUnseenChildren = 0; if (sgi.threaded) { int cnx = nx + 1; while (cnx < xmsgs.length) { SonicleIMAPMessage cxm = (SonicleIMAPMessage) xmsgs[cnx]; if (cxm.isExpunged()) { cnx++; continue; } while (cxm.getThreadIndent() > 0) { tChildren = true; if (!cxm.isExpunged() && !cxm.isSet(Flags.Flag.SEEN)) ++tUnseenChildren; ++cnx; if (cnx >= xmsgs.length) break; cxm = (SonicleIMAPMessage) xmsgs[cnx]; } break; } } Flags flags = xm.getFlags(); //Date java.util.Date d = xm.getSentDate(); if (d == null) d = xm.getReceivedDate(); if (d == null) d = new java.util.Date(0); cal.setTime(d); int yyyy = cal.get(java.util.Calendar.YEAR); int mm = cal.get(java.util.Calendar.MONTH); int dd = cal.get(java.util.Calendar.DAY_OF_MONTH); int hhh = cal.get(java.util.Calendar.HOUR_OF_DAY); int mmm = cal.get(java.util.Calendar.MINUTE); int sss = cal.get(java.util.Calendar.SECOND); //From String from = ""; String fromemail = ""; Address ia[] = xm.getFrom(); if (ia != null) { InternetAddress iafrom = (InternetAddress) ia[0]; from = iafrom.getPersonal(); if (from == null) from = iafrom.getAddress(); fromemail = iafrom.getAddress(); } from = (from == null ? "" : StringEscapeUtils.escapeEcmaScript(MailUtils.htmlescape(from))); fromemail = (fromemail == null ? "" : StringEscapeUtils.escapeEcmaScript(MailUtils.htmlescape(fromemail))); //To String to = ""; String toemail = ""; ia = xm.getRecipients(Message.RecipientType.TO); //if not sent and not shared, show me first if in TO if (ia != null) { InternetAddress iato = (InternetAddress) ia[0]; if (!issent && !isundershared) { for (Address ax : ia) { InternetAddress iax = (InternetAddress) ax; if (iax.getAddress().equals(profile.getEmailAddress())) { iato = iax; break; } } } to = iato.getPersonal(); if (to == null) to = iato.getAddress(); toemail = iato.getAddress(); } to = (to == null ? "" : StringEscapeUtils.escapeEcmaScript(MailUtils.htmlescape(to))); toemail = (toemail == null ? "" : StringEscapeUtils.escapeEcmaScript(MailUtils.htmlescape(toemail))); //Subject String subject = xm.getSubject(); if (subject != null) { try { subject = MailUtils.decodeQString(subject); } catch (Exception exc) { } } else subject = ""; /* if (threaded) { if (tIndent>0) { StringBuffer sb=new StringBuffer(); for(int w=0;w<tIndent;++w) sb.append(" "); subject=sb+subject; } }*/ boolean hasAttachments = mcache.hasAttachements(xm); subject = StringEscapeUtils.escapeEcmaScript(MailUtils.htmlescape(subject)); //Unread boolean unread = !xm.isSet(Flags.Flag.SEEN); if (queryObj != null && unread) ++funread; //Priority int priority = getPriority(xm); //Status java.util.Date today = new java.util.Date(); java.util.Calendar cal1 = java.util.Calendar.getInstance(locale); java.util.Calendar cal2 = java.util.Calendar.getInstance(locale); boolean isToday = false; String gdate = ""; String sdate = ""; String xdate = ""; if (d != null) { java.util.Date gd = sgi.threaded ? xm.getMostRecentThreadDate() : d; cal1.setTime(today); cal2.setTime(gd); gdate = DateFormat.getDateInstance(DateFormat.MEDIUM, locale).format(gd); sdate = cal2.get(java.util.Calendar.YEAR) + "/" + String.format("%02d", (cal2.get(java.util.Calendar.MONTH) + 1)) + "/" + String.format("%02d", cal2.get(java.util.Calendar.DATE)); //boolean isGdate=group.equals("gdate"); if (cal1.get(java.util.Calendar.MONTH) == cal2.get(java.util.Calendar.MONTH) && cal1.get(java.util.Calendar.YEAR) == cal2.get(java.util.Calendar.YEAR)) { int dx = cal1.get(java.util.Calendar.DAY_OF_MONTH) - cal2.get(java.util.Calendar.DAY_OF_MONTH); if (dx == 0) { isToday = true; //if (isGdate) { // gdate=WT.lookupCoreResource(locale, CoreLocaleKey.WORD_DATE_TODAY)+" "+gdate; //} xdate = WT.lookupCoreResource(locale, CoreLocaleKey.WORD_DATE_TODAY); } else if (dx == 1 /*&& isGdate*/) { xdate = WT.lookupCoreResource(locale, CoreLocaleKey.WORD_DATE_YESTERDAY); } } } String status = "read"; if (flags != null) { if (flags.contains(Flags.Flag.ANSWERED)) { if (flags.contains("$Forwarded")) status = "repfwd"; else status = "replied"; } else if (flags.contains("$Forwarded")) { status = "forwarded"; } else if (flags.contains(Flags.Flag.SEEN)) { status = "read"; } else if (isToday) { status = "new"; } else { status = "unread"; } // if (flags.contains(Flags.Flag.USER)) flagImage=webtopapp.getUri()+"/images/themes/"+profile.getTheme()+"/mail/flag.gif"; } //Size int msgsize = 0; msgsize = (xm.getSize() * 3) / 4;// /1024 + 1; //User flags String cflag = ""; for (WebtopFlag webtopFlag : webtopFlags) { String flagstring = webtopFlag.label; //String tbflagstring=webtopFlag.tbLabel; if (!flagstring.equals("complete")) { String oldflagstring = "flag" + flagstring; if (flags.contains(flagstring) || flags.contains(oldflagstring) /*|| (tbflagstring!=null && flags.contains(tbflagstring))*/ ) { cflag = flagstring; } } } boolean flagComplete = flags.contains("complete"); if (flagComplete) { if (cflag.length() > 0) cflag += "-complete"; else cflag = "complete"; } if (cflag.length() == 0 && flags.contains(Flags.Flag.FLAGGED)) cflag = "special"; boolean hasNote = flags.contains(sflagNote); String svtags = getJSTagsArray(flags); boolean autoedit = false; boolean issched = false; int syyyy = 0; int smm = 0; int sdd = 0; int shhh = 0; int smmm = 0; int ssss = 0; if (isdrafts) { String h = getSingleHeaderValue(xm, "Sonicle-send-scheduled"); if (h != null && h.equals("true")) { java.util.Calendar scal = parseScheduleHeader( getSingleHeaderValue(xm, "Sonicle-send-date"), getSingleHeaderValue(xm, "Sonicle-send-time")); if (scal != null) { syyyy = scal.get(java.util.Calendar.YEAR); smm = scal.get(java.util.Calendar.MONTH); sdd = scal.get(java.util.Calendar.DAY_OF_MONTH); shhh = scal.get(java.util.Calendar.HOUR_OF_DAY); smmm = scal.get(java.util.Calendar.MINUTE); ssss = scal.get(java.util.Calendar.SECOND); issched = true; status = "scheduled"; } } h = getSingleHeaderValue(xm, HEADER_SONICLE_FROM_DRAFTER); if (h != null && h.equals("true")) { autoedit = true; } } String xmfoldername = xm.getFolder().getFullName(); //idmessage=idmessage.replaceAll("\\\\", "\\\\"); //idmessage=Utils.jsEscape(idmessage); if (i > 0) sout += ",\n"; boolean archived = false; if (hasDmsDocumentArchiving()) { archived = xm.getHeader("X-WT-Archived") != null; if (!archived) { archived = flags.contains(sflagDmsArchived); } } String msgtext = null; if (us.getShowMessagePreviewOnRow() && isToday && unread) { try { msgtext = MailUtils.peekText(xm); if (msgtext != null) { msgtext = msgtext.trim(); if (msgtext.length() > 100) msgtext = msgtext.substring(0, 100); } } catch (MessagingException | IOException ex1) { msgtext = ex1.getMessage(); } } String pecstatus = null; if (messagesInfo.isPEC()) { String hdrs[] = xm.getHeader(HDR_PEC_TRASPORTO); if (hdrs != null && hdrs.length > 0 && (hdrs[0].equals("errore") || hdrs[0].equals("posta-certificata"))) pecstatus = hdrs[0]; else { hdrs = xm.getHeader(HDR_PEC_RICEVUTA); if (hdrs != null && hdrs.length > 0) pecstatus = hdrs[0]; } } sout += "{idmessage:'" + nuid + "'," + "priority:" + priority + "," + "status:'" + status + "'," + "to:'" + to + "'," + "toemail:'" + toemail + "'," + "from:'" + from + "'," + "fromemail:'" + fromemail + "'," + "subject:'" + subject + "'," + (msgtext != null ? "msgtext: '" + StringEscapeUtils.escapeEcmaScript(msgtext) + "'," : "") + (sgi.threaded ? "threadId: " + tId + "," : "") + (sgi.threaded ? "threadIndent:" + tIndent + "," : "") + "date: new Date(" + yyyy + "," + mm + "," + dd + "," + hhh + "," + mmm + "," + sss + ")," + "gdate: '" + gdate + "'," + "sdate: '" + sdate + "'," + "xdate: '" + xdate + "'," + "unread: " + unread + "," + "size:" + msgsize + "," + (svtags != null ? "tags: " + svtags + "," : "") + (pecstatus != null ? "pecstatus: '" + pecstatus + "'," : "") + "flag:'" + cflag + "'" + (hasNote ? ",note:true" : "") + (archived ? ",arch:true" : "") + (isToday ? ",istoday:true" : "") + (hasAttachments ? ",atts:true" : "") + (issched ? ",scheddate: new Date(" + syyyy + "," + smm + "," + sdd + "," + shhh + "," + smmm + "," + ssss + ")" : "") + (sgi.threaded && tIndent == 0 ? ",threadOpen: " + mcache.isThreadOpen(nuid) : "") + (sgi.threaded && tIndent == 0 ? ",threadHasChildren: " + tChildren : "") + (sgi.threaded && tIndent == 0 ? ",threadUnseenChildren: " + tUnseenChildren : "") + (sgi.threaded && xm.hasThreads() && !xm.isMostRecentInThread() ? ",fmtd: true" : "") + (sgi.threaded && !xmfoldername.equals(folder.getFullName()) ? ",fromfolder: '" + StringEscapeUtils.escapeEcmaScript(xmfoldername) + "'" : "") + "}"; if (autoedit) { autoeditList.add(nuid); } // sout+="{messageid:'"+m.getMessageID()+"',from:'"+from+"',subject:'"+subject+"',date: new Date("+yyyy+","+mm+","+dd+"),unread: "+unread+"},\n"; } if (openedsent) fsent.close(false); } /* if (ppattern==null && !isSpecialFolder(mcache.getFolderName())) { //if (max<msgs.length) mcache.fetch(msgs,FolderCache.flagsFP,max,msgs.length); for(int i=max;i<msgs.length;++i) { try { if (!msgs[i].isSet(Flags.Flag.SEEN)) funread++; } catch(Exception exc) { } } } else { funread=mcache.getUnreadMessagesCount(); }*/ if (mcache.isScanForcedOrEnabled()) { //Send message only if first page if (start == 0) mcache.refreshUnreads(); funread = mcache.getUnreadMessagesCount(); } else funread = 0; long qlimit = -1; long qusage = -1; try { Quota quotas[] = account.getQuota("INBOX"); if (quotas != null) for (Quota q : quotas) { if ((q.quotaRoot.equals("INBOX") || q.quotaRoot.equals("Quota")) && q.resources != null) { for (Quota.Resource r : q.resources) { if (r.name.equals("STORAGE")) { qlimit = r.limit; qusage = r.usage; } } } } } catch (MessagingException exc) { logger.debug("Error on QUOTA", exc); } sout += "\n],\n"; sout += "total: " + (total - expunged) + ",\n"; if (qlimit >= 0 && qusage >= 0) sout += "quotaLimit: " + qlimit + ", quotaUsage: " + qusage + ",\n"; if (messagesInfo.isPEC()) sout += "isPEC: true,\n"; sout += "realTotal: " + (xmsgs.length - expunged) + ",\n"; sout += "expunged: " + (expunged) + ",\n"; } else { sout += "messages: [],\n" + "total: 0,\n" + "realTotal: 0,\n" + "expunged:0,\n"; } sout += "metaData: {\n" + " root: 'messages', total: 'total', idProperty: 'idmessage',\n" + " fields: ['idmessage','priority','status','to','from','subject','date','gdate','unread','size','flag','note','arch','istoday','atts','scheddate','fmtd','fromfolder'],\n" + " sortInfo: { field: '" + psortfield + "', direction: '" + psortdir + "' },\n" + " threaded: " + sgi.threaded + ",\n" + " groupField: '" + (sgi.threaded ? "threadId" : group) + "',\n"; /* ColumnVisibilitySetting cvs = us.getColumnVisibilitySetting(pfoldername); ColumnsOrderSetting cos = us.getColumnsOrderSetting(); // Apply grid defaults //ColumnVisibilitySetting.applyDefaults(mcache.isSent(), cvs); ColumnVisibilitySetting.applyDefaults(issent||isundersent, cvs); if (autoeditList.size()>0) { sout+="autoedit: ["; for(long muid: autoeditList) { sout+=muid+","; } if(StringUtils.right(sout, 1).equals(",")) sout = StringUtils.left(sout, sout.length()-1); sout+="],\n"; } // Fills columnsInfo object for client rendering sout += "colsInfo2: ["; for (String dataIndex : cvs.keySet()) { sout += "{dataIndex:'" + dataIndex + "',hidden:" + String.valueOf(!cvs.get(dataIndex)) + ",index:"+cos.indexOf(dataIndex)+"},"; } if (StringUtils.right(sout, 1).equals(",")) { sout = StringUtils.left(sout, sout.length() - 1); } sout += "]\n";*/ sout += "},\n"; sout += "threaded: " + (sgi.threaded ? "1" : "0") + ",\n"; sout += "unread: " + funread + ", issent: " + issent + ", millis: " + messagesInfo.millis + " }\n"; } else { sout += "total:0,\nstart:0,\nlimit:0,\nmessages: [\n"; sout += "\n], unread: 0, issent: false }\n"; } out.println(sout); } catch (Exception exc) { new JsonResult(exc).printTo(out); Service.logger.error("Exception", exc); } }
From source file:com.codename1.impl.android.AndroidImplementation.java
/** * @inheritDoc//ww w . j a v a 2 s.c o m */ public L10NManager getLocalizationManager() { if (l10n == null) { Locale l = Locale.getDefault(); l10n = new L10NManager(l.getLanguage(), l.getCountry()) { public double parseDouble(String localeFormattedDecimal) { try { return NumberFormat.getNumberInstance().parse(localeFormattedDecimal).doubleValue(); } catch (ParseException err) { return Double.parseDouble(localeFormattedDecimal); } } public String format(int number) { return NumberFormat.getNumberInstance().format(number); } public String format(double number) { return NumberFormat.getNumberInstance().format(number); } public String formatCurrency(double currency) { return NumberFormat.getCurrencyInstance().format(currency); } public String formatDateLongStyle(Date d) { return DateFormat.getDateInstance(DateFormat.LONG).format(d); } public String formatDateShortStyle(Date d) { return DateFormat.getDateInstance(DateFormat.SHORT).format(d); } public String formatDateTime(Date d) { return DateFormat.getDateTimeInstance().format(d); } public String formatDateTimeMedium(Date d) { DateFormat dd = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM); return dd.format(d); } public String formatDateTimeShort(Date d) { DateFormat dd = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT); return dd.format(d); } public String getCurrencySymbol() { return NumberFormat.getInstance().getCurrency().getSymbol(); } public void setLocale(String locale, String language) { super.setLocale(locale, language); Locale l = new Locale(language, locale); Locale.setDefault(l); } }; } return l10n; }
From source file:com.sonicle.webtop.mail.Service.java
public void processGetMessage(HttpServletRequest request, HttpServletResponse response, PrintWriter out) { MailAccount account = getAccount(request); String pfoldername = request.getParameter("folder"); String puidmessage = request.getParameter("idmessage"); String pidattach = request.getParameter("idattach"); String providername = request.getParameter("provider"); String providerid = request.getParameter("providerid"); String nopec = request.getParameter("nopec"); int idattach = 0; boolean isEditor = request.getParameter("editor") != null; boolean setSeen = ServletUtils.getBooleanParameter(request, "setseen", true); if (df == null) { df = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.MEDIUM, environment.getProfile().getLocale()); }//from ww w .ja v a 2 s.co m try { FolderCache mcache = null; Message m = null; IMAPMessage im = null; int recs = 0; long msguid = -1; String vheader[] = null; boolean wasseen = false; boolean isPECView = false; String sout = "{\nmessage: [\n"; if (providername == null) { account.checkStoreConnected(); mcache = account.getFolderCache(pfoldername); msguid = Long.parseLong(puidmessage); m = mcache.getMessage(msguid); im = (IMAPMessage) m; im.setPeek(us.isManualSeen()); if (m.isExpunged()) throw new MessagingException("Message " + puidmessage + " expunged"); vheader = m.getHeader("Disposition-Notification-To"); wasseen = m.isSet(Flags.Flag.SEEN); if (pidattach != null) { HTMLMailData mailData = mcache.getMailData((MimeMessage) m); Part part = mailData.getAttachmentPart(Integer.parseInt(pidattach)); m = (Message) part.getContent(); idattach = Integer.parseInt(pidattach) + 1; } else if (nopec == null && mcache.isPEC()) { String hdrs[] = m.getHeader(HDR_PEC_TRASPORTO); if (hdrs != null && hdrs.length > 0 && hdrs[0].equals("posta-certificata")) { HTMLMailData mailData = mcache.getMailData((MimeMessage) m); int parts = mailData.getAttachmentPartCount(); for (int i = 0; i < parts; ++i) { Part p = mailData.getAttachmentPart(i); if (p.isMimeType("message/rfc822")) { m = (Message) p.getContent(); idattach = i + 1; isPECView = true; break; } } } } } else { // TODO: provider get message!!!! /* WebTopService provider=wts.getServiceByName(providername); MessageContentProvider mcp=provider.getMessageContentProvider(providerid); m=new MimeMessage(session,mcp.getSource()); mcache=fcProvided; mcache.addProvidedMessage(providername, providerid, m);*/ } String messageid = getMessageID(m); String subject = m.getSubject(); if (subject == null) { subject = ""; } else { try { subject = MailUtils.decodeQString(subject); } catch (Exception exc) { } } java.util.Date d = m.getSentDate(); if (d == null) { d = m.getReceivedDate(); } if (d == null) { d = new java.util.Date(0); } String date = df.format(d).replaceAll("\\.", ":"); String fromName = ""; String fromEmail = ""; Address as[] = m.getFrom(); InternetAddress iafrom = null; if (as != null && as.length > 0) { iafrom = (InternetAddress) as[0]; fromName = iafrom.getPersonal(); fromEmail = adjustEmail(iafrom.getAddress()); if (fromName == null) { fromName = fromEmail; } } sout += "{iddata:'from',value1:'" + StringEscapeUtils.escapeEcmaScript(MailUtils.htmlescape(fromName)) + "',value2:'" + StringEscapeUtils.escapeEcmaScript(fromEmail) + "',value3:0},\n"; recs += 2; Address tos[] = m.getRecipients(RecipientType.TO); if (tos != null) { for (Address to : tos) { InternetAddress ia = (InternetAddress) to; String toName = ia.getPersonal(); String toEmail = adjustEmail(ia.getAddress()); if (toName == null) { toName = toEmail; } sout += "{iddata:'to',value1:'" + StringEscapeUtils.escapeEcmaScript(MailUtils.htmlescape(toName)) + "',value2:'" + StringEscapeUtils.escapeEcmaScript(toEmail) + "',value3:0},\n"; ++recs; } } Address ccs[] = m.getRecipients(RecipientType.CC); if (ccs != null) { for (Address cc : ccs) { InternetAddress ia = (InternetAddress) cc; String ccName = ia.getPersonal(); String ccEmail = adjustEmail(ia.getAddress()); if (ccName == null) { ccName = ccEmail; } sout += "{iddata:'cc',value1:'" + StringEscapeUtils.escapeEcmaScript(ccName) + "',value2:'" + StringEscapeUtils.escapeEcmaScript(ccEmail) + "',value3:0},\n"; ++recs; } } Address bccs[] = m.getRecipients(RecipientType.BCC); if (bccs != null) for (Address bcc : bccs) { InternetAddress ia = (InternetAddress) bcc; String bccName = ia.getPersonal(); String bccEmail = adjustEmail(ia.getAddress()); if (bccName == null) { bccName = bccEmail; } sout += "{iddata:'bcc',value1:'" + StringEscapeUtils.escapeEcmaScript(bccName) + "',value2:'" + StringEscapeUtils.escapeEcmaScript(bccEmail) + "',value3:0},\n"; ++recs; } ArrayList<String> htmlparts = null; boolean balanceTags = isPreviewBalanceTags(iafrom); if (providername == null) { htmlparts = mcache.getHTMLParts((MimeMessage) m, msguid, false, balanceTags); } else { htmlparts = mcache.getHTMLParts((MimeMessage) m, providername, providerid, balanceTags); } HTMLMailData mailData = mcache.getMailData((MimeMessage) m); ICalendarRequest ir = mailData.getICalRequest(); if (ir != null) { if (htmlparts.size() > 0) sout += "{iddata:'html',value1:'" + StringEscapeUtils.escapeEcmaScript(htmlparts.get(0)) + "',value2:'',value3:0},\n"; } else { for (String html : htmlparts) { //sout += "{iddata:'html',value1:'" + OldUtils.jsEscape(html) + "',value2:'',value3:0},\n"; sout += "{iddata:'html',value1:'" + StringEscapeUtils.escapeEcmaScript(html) + "',value2:'',value3:0},\n"; ++recs; } } /*if (!wasseen) { //if (us.isManualSeen()) { if (!setSeen) { m.setFlag(Flags.Flag.SEEN, false); } else { //if no html part, flag seen is not set if (htmlparts.size()==0) m.setFlag(Flags.Flag.SEEN, true); } }*/ if (!us.isManualSeen()) { if (htmlparts.size() == 0) m.setFlag(Flags.Flag.SEEN, true); } else { if (setSeen) m.setFlag(Flags.Flag.SEEN, true); } int acount = mailData.getAttachmentPartCount(); for (int i = 0; i < acount; ++i) { Part p = mailData.getAttachmentPart(i); String ctype = p.getContentType(); Service.logger.debug("attachment " + i + " is " + ctype); int ix = ctype.indexOf(';'); if (ix > 0) { ctype = ctype.substring(0, ix); } String cidnames[] = p.getHeader("Content-ID"); String cidname = null; if (cidnames != null && cidnames.length > 0) cidname = mcache.normalizeCidFileName(cidnames[0]); boolean isInlineable = isInlineableMime(ctype); boolean inline = ((p.getHeader("Content-Location") != null) || (cidname != null)) && isInlineable; if (inline && cidname != null) inline = mailData.isReferencedCid(cidname); if (p.getDisposition() != null && p.getDisposition().equalsIgnoreCase(Part.INLINE) && inline) { continue; } String imgname = null; boolean isCalendar = ctype.equalsIgnoreCase("text/calendar") || ctype.equalsIgnoreCase("text/icalendar"); if (isCalendar) { imgname = "resources/" + getManifest().getId() + "/laf/" + cus.getLookAndFeel() + "/ical_16.png"; } String pname = getPartName(p); try { pname = MailUtils.decodeQString(pname); } catch (Exception exc) { } if (pname == null) { ix = ctype.indexOf("/"); String fname = ctype; if (ix > 0) { fname = ctype.substring(ix + 1); } //String ext = WT.getMediaTypeExtension(ctype); //if (ext == null) { pname = fname; //} else { // pname = fname + "." + ext; //} if (isCalendar) pname += ".ics"; } else { if (isCalendar && !StringUtils.endsWithIgnoreCase(pname, ".ics")) pname += ".ics"; } int size = p.getSize(); int lines = (size / 76); int rsize = size - (lines * 2);//(p.getSize()/4)*3; String iddata = ctype.equalsIgnoreCase("message/rfc822") ? "eml" : (inline ? "inlineattach" : "attach"); boolean editable = isFileEditableInDocEditor(pname); sout += "{iddata:'" + iddata + "',value1:'" + (i + idattach) + "',value2:'" + StringEscapeUtils.escapeEcmaScript(MailUtils.htmlescape(pname)) + "',value3:" + rsize + ",value4:" + (imgname == null ? "null" : "'" + StringEscapeUtils.escapeEcmaScript(imgname) + "'") + ", editable: " + editable + " },\n"; } if (!mcache.isDrafts() && !mcache.isSent() && !mcache.isSpam() && !mcache.isTrash() && !mcache.isArchive()) { if (vheader != null && vheader[0] != null && !wasseen) { sout += "{iddata:'receipt',value1:'" + us.getReadReceiptConfirmation() + "',value2:'" + StringEscapeUtils.escapeEcmaScript(vheader[0]) + "',value3:0},\n"; } } String h = getSingleHeaderValue(m, "Sonicle-send-scheduled"); if (h != null && h.equals("true")) { java.util.Calendar scal = parseScheduleHeader(getSingleHeaderValue(m, "Sonicle-send-date"), getSingleHeaderValue(m, "Sonicle-send-time")); if (scal != null) { java.util.Date sd = scal.getTime(); String sdate = df.format(sd).replaceAll("\\.", ":"); sout += "{iddata:'scheddate',value1:'" + StringEscapeUtils.escapeEcmaScript(sdate) + "',value2:'',value3:0},\n"; } } if (ir != null) { /* ICalendarManager calMgr = (ICalendarManager)WT.getServiceManager("com.sonicle.webtop.calendar",environment.getProfileId()); if (calMgr != null) { if (ir.getMethod().equals("REPLY")) { calMgr.updateEventFromICalReply(ir.getCalendar()); //TODO: gestire lato client una notifica di avvenuto aggiornamento } else { Event evt = calMgr..getEvent(GetEventScope.PERSONAL_AND_INCOMING, false, ir.getUID()) if (evt != null) { UserProfileId pid = getEnv().getProfileId(); UserProfile.Data ud = WT.getUserData(pid); boolean iAmOrganizer = StringUtils.equalsIgnoreCase(evt.getOrganizerAddress(), ud.getEmailAddress()); boolean iAmOwner = pid.equals(calMgr.getCalendarOwner(evt.getCalendarId())); if (!iAmOrganizer && !iAmOwner) { //TODO: gestire lato client l'aggiornamento: Accetta/Rifiuta, Aggiorna e20 dopo update/request } } } } */ ICalendarManager cm = (ICalendarManager) WT.getServiceManager("com.sonicle.webtop.calendar", true, environment.getProfileId()); if (cm != null) { int eid = -1; //Event ev=cm.getEventByScope(EventScope.PERSONAL_AND_INCOMING, ir.getUID()); Event ev = null; if (ir.getMethod().equals("REPLY")) { // Previous impl. forced (forceOriginal == true) ev = cm.getEvent(GetEventScope.PERSONAL_AND_INCOMING, ir.getUID()); } else { ev = cm.getEvent(GetEventScope.PERSONAL_AND_INCOMING, ir.getUID()); } UserProfileId pid = getEnv().getProfileId(); UserProfile.Data ud = WT.getUserData(pid); if (ev != null) { InternetAddress organizer = InternetAddressUtils.toInternetAddress(ev.getOrganizer()); boolean iAmOwner = pid.equals(cm.getCalendarOwner(ev.getCalendarId())); boolean iAmOrganizer = (organizer != null) && StringUtils.equalsIgnoreCase(organizer.getAddress(), ud.getEmailAddress()); //TODO: in reply controllo se mail combacia con quella dell'attendee che risponde... //TODO: rimuovere controllo su data? dovrebbe sempre aggiornare? if (iAmOwner || iAmOrganizer) { eid = 0; //TODO: troviamo un modo per capire se la risposta si riverisce all'ultima versione dell'evento? Nuovo campo timestamp? /* DateTime dtEvt = ev.getRevisionTimestamp().withMillisOfSecond(0).withZone(DateTimeZone.UTC); DateTime dtICal = ICal4jUtils.fromICal4jDate(ir.getLastModified(), ICal4jUtils.getTimeZone(DateTimeZone.UTC)); if (dtICal.isAfter(dtEvt)) { eid = 0; } else { eid = ev.getEventId(); } */ } } sout += "{iddata:'ical',value1:'" + ir.getMethod() + "',value2:'" + ir.getUID() + "',value3:'" + eid + "'},\n"; } } sout += "{iddata:'date',value1:'" + StringEscapeUtils.escapeEcmaScript(date) + "',value2:'',value3:0},\n"; sout += "{iddata:'subject',value1:'" + StringEscapeUtils.escapeEcmaScript(MailUtils.htmlescape(subject)) + "',value2:'',value3:0},\n"; sout += "{iddata:'messageid',value1:'" + StringEscapeUtils.escapeEcmaScript(messageid) + "',value2:'',value3:0}\n"; if (providername == null && !mcache.isSpecial()) { mcache.refreshUnreads(); } long millis = System.currentTimeMillis(); sout += "\n],\n"; String svtags = getJSTagsArray(m.getFlags()); if (svtags != null) sout += "tags: " + svtags + ",\n"; if (isPECView) { sout += "pec: true,\n"; } sout += "total:" + recs + ",\nmillis:" + millis + "\n}\n"; out.println(sout); if (im != null) im.setPeek(false); // if (!wasopen) folder.close(false); } catch (Exception exc) { Service.logger.error("Exception", exc); } }