/** * Helper to create an ICS calendar from a list of vevents, then turn it into an attachment * @param vevents list of vevents * @param method the ITIP method for the calendar, e.g. "REQUEST" * @return */ private Attachment formatICSAttachment(List<VEvent> vevents, String method) { String path = calendarHelper.createCalendarFile(vevents, method); // It's possible that ICS creation failed if (StringUtils.isBlank(path)) { return null; } // Explicitly define the Content-Type and Content-Diposition headers so the invitation appears inline String filename = StringUtils.substringAfterLast(path, File.separator); String type = String.format("text/calendar; charset=\"utf-8\"; method=%s; name=signup-invite.ics", method); File file = new File(path); DataSource dataSource = new Attachment.RenamedDataSource(new FileDataSource(file), filename); return new Attachment(dataSource, type, Attachment.ContentDisposition.INLINE); }
/** * Creates a attachment based on a file. * @param file The file to load the contents of the attachement from and to get the mimetype * from. * @param filename The filename to call the attachment when sent out, doesn't have to match * the file from which the content is loaded. * @deprecated {@link org.sakaiproject.email.api.Attachment#Attachment(javax.activation.DataSource)} */ public Attachment(File file, String filename) { this(new RenamedDataSource(new FileDataSource(file), filename)); }
/** * Creates an attachment supplying an different filename. * @param dataSource The data source. * @param filename The alternative filename. */ public Attachment(DataSource dataSource, String filename) { this(new RenamedDataSource(dataSource, filename), null, null); }
/** * Creates an attachment supplying an different filename. * @param dataSource The data source. * @param filename The alternative filename. */ public Attachment(DataSource dataSource, String filename) { this(new RenamedDataSource(dataSource, filename), null, null); }
/** * Creates a attachment based on a file. * @param file The file to load the contents of the attachement from and to get the mimetype * from. * @param filename The filename to call the attachment when sent out, doesn't have to match * the file from which the content is loaded. * @deprecated {@link org.sakaiproject.email.api.Attachment#Attachment(javax.activation.DataSource)} */ public Attachment(File file, String filename) { this(new RenamedDataSource(new FileDataSource(file), filename)); }