Add multiple events to ical with biweekly - icalendar

I have the following method that uses biweekly to create and ics string:
public String createICalendarString(List<ICalendarEventVo> iCalendarEventVos, String locale, String timeZoneCanonicalId) throws IOException
{
String icsLocale = convertLocaleToIcsFormat(locale);
ICalendar ical = new ICalendar();
for (ICalendarEventVo iCalendarEventVo : iCalendarEventVos)
{
VEvent event = new VEvent();
Summary summary = new Summary(iCalendarEventVo.getSummaryText());
summary.setLanguage(icsLocale);
event.setSummary(summary);
if (null != iCalendarEventVo.getDescriptionText())
{
Description description = new Description(iCalendarEventVo.getDescriptionText());
description.setLanguage(icsLocale);
event.setDescription(description);
}
if (null != iCalendarEventVo.getLocationText())
{
Location location = new Location(iCalendarEventVo.getLocationText());
location.setLanguage(icsLocale);
event.setLocation(location);
}
if (null != iCalendarEventVo.getOrganizerName() && null != iCalendarEventVo.getOrganizerEmail())
{
Organizer organizer = new Organizer(iCalendarEventVo.getOrganizerName(), iCalendarEventVo.getOrganizerEmail());
event.setOrganizer(organizer);
}
event.setDateStart(iCalendarEventVo.getStartDate());
event.setDateEnd(iCalendarEventVo.getEndDate());
event.setUid(iCalendarEventVo.getUid());
ical.addEvent(event);
}
String icsString = null;
try (StringWriter writer = new StringWriter();
ICalWriter icalWriter = new ICalWriter(writer, ICalVersion.V2_0);)
{
//optional: Use Outlook-friendly VTIMEZONE components:
icalWriter.getTimezoneInfo().setGenerator(new TzUrlDotOrgGenerator(true));
//output date/time values in the timeZone that was passed in
TimeZone timeZone = TimeZone.getTimeZone(timeZoneCanonicalId);
icalWriter.getTimezoneInfo().setDefaultTimeZone(timeZone);
icalWriter.write(ical);
icsString = writer.toString();
}
return icsString;
}
Which generates the following:
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//Michael Angstadt//biweekly 0.4.4//EN
BEGIN:VEVENT
DTSTAMP:20151128T030141Z
SUMMARY;LANGUAGE=en-us:Test ILT Class: Session #1
DESCRIPTION;LANGUAGE=en-us:Test ILT Class goes through what is needed to ma
ke a sale. The session will be about looking nice for your customer.
LOCATION;LANGUAGE=en-us:Statue of Liberty - Meet at the top of the crown.
ORGANIZER;CN=TorchLMS:mailto:no-reply#torchlms.com
DTSTART;TZID=America/New_York:20151201T190000
DTEND;TZID=America/New_York:20151201T220000
UID:TLMS_SESSION_1000110010000000000_1000110210000000051
END:VEVENT
BEGIN:VEVENT
DTSTAMP:20151128T030141Z
SUMMARY;LANGUAGE=en-us:Test ILT Class: Session #2
DESCRIPTION;LANGUAGE=en-us:Test ILT Class goes through what is needed to ma
ke a sale. This session will talk about how to blow sunshine in the direct
ion of the customer.
LOCATION;LANGUAGE=en-us:World Trade Center - Top floor in the penthouse
ORGANIZER;CN=TorchLMS:mailto:no-reply#torchlms.com
DTSTART;TZID=America/New_York:20151202T170000
DTEND;TZID=America/New_York:20151202T190000
UID:TLMS_SESSION_1000110010000000000_1000110210000000101
END:VEVENT
BEGIN:VTIMEZONE
TZID:America/New_York
TZURL:http://tzurl.org/zoneinfo-outlook/America/New_York
X-LIC-LOCATION:America/New_York
BEGIN:DAYLIGHT
TZOFFSETFROM:-0500
TZOFFSETTO:-0400
TZNAME:EDT
DTSTART:19700308T020000
RRULE:FREQ=YEARLY;BYDAY=2SU;BYMONTH=3
END:DAYLIGHT
BEGIN:STANDARD
TZOFFSETFROM:-0400
TZOFFSETTO:-0500
TZNAME:EST
DTSTART:19701101T020000
RRULE:FREQ=YEARLY;BYDAY=1SU;BYMONTH=11
END:STANDARD
END:VTIMEZONE
END:VCALENDAR
The problem is when I email this to my gmail account only the first event shows up. At first I thought this was an issue with Biweekly, but it looks like the ics out put is correct. Is there something wrong with the ics output?

If you are sending this ics stream via email, you should have a METHOD:PUBLISH property at the beginning of your VCALENDAR object and follow the rules of iTIP (https://www.rfc-editor.org/rfc/rfc5546) and iMIP (https://www.rfc-editor.org/rfc/rfc6047).
Once you are done, it is also quite possible that some clients (e.g. gmail) do not accept multiple events in the same calendar invitation.
A last (rather aesthetic) comment: the VTIMEZONE component is usually placed at the top of the iCalendar stream.

Hi tad: It worked for me. Here is how I did it:
Click on the little down arrow to the right of "My calendars" and select "Settings".
Click on "Import Calendar" (next to the "Create calendar" button).
Select the .ics file in the file chooser.
Note the name of the calendar that's selected in the "Calendar" dropdown list.
Click "Import".
A dialog box appears that says something like "2 events imported".
Make sure the calendar from step 4 is visible, and go to 12/1 and 12/2 to see the events.

Related

Utilities.formatDate() in Google Apps Script outputs previous date (e.g. input 25.05.2015 -> output 24.05.2015)

I have a problem with Google Docs' Utilities.formatDate() function.
I have a spreadsheet that contains all of the orders we place in the lab. When an order is delivered our lab manager enters the delivery date in the relevant cell in such a spreadsheet, in the following format: dd.MM.yyyy.
I created a script that, provided certain conditions, will email whoever placed that order alerting them that the order has been delivered on that particular date. Here is the code:
function DeliveryAlerts() {
try {
var email_dict = {"Y":"Y#Z.com"}
var spreadsheet = SpreadsheetApp.openById("ABC");
SpreadsheetApp.setActiveSpreadsheet(spreadsheet);
var sheet = spreadsheet.getSheetByName("Orders");
var values = sheet.getRange("A2:Q251").getValues();
var bgcolours = sheet.getRange("A2:Q251").getBackgrounds();
for(var i=0;i<=249;i++)
{
var j = i + 2;
if (values[i][16]=="Yes" && values[i][11]!="" && bgcolours[i][16]!="#b8b8b8")
{
var email_address = email_dict[values[i][13]];
var cur_date = Utilities.formatDate(values[i][11], "GMT+1", "EEE dd.MM.yyyy");
var message = "Hello there,\n\nYour order of " + values[i][4] + " has been delivered on "+ cur_date +".\n\nBest wishes";
var subject = "Delivery alert";
MailApp.sendEmail(email_address, subject, message,{replyTo:"abc#abc.com", name:"ABC"});
sheet.getRange("Q"+j).setBackground("#b8b8b8");
}
}
} catch (err) {
MailApp.sendEmail("abc#abc.com", "Delivery Alerts Script in Order Master List", err);
}
}
I use
Utilities.formatDate(values[i][11], "GMT+1", "EEE dd.MM.yyyy") to reformat the date from, say, 25.05.2015 (that is, the value in the cell) to Mon 25.05.2015. However, what I get instead is Sun 24.05.2015.
Does anybody know what is going on?
Thank you in advance.
Nicola
Check the time zone setting in the script editor. Under the FILE menu, choose PROJECT PROPERTIES in the script editor. It's possible to have a different time zone setting in Apps Script, than is in the spreadsheet. This is a common issue that arises. Apps Script allows a separate time zone setting from the spreadsheet. Also, even if the time is only off by one minute, if the time setting of the date is all zeros, it's common to get the problem that you are having. When a user enters a date, it's possible that no time setting is made. So the time is set to all zeros. The date is correct, but the time is all zeros. Even if the date was typed in at 3 in the afternoon, for example, and the date is correct, the time setting can be midnight of that day. So, even if you subtracted one second from that date, it would now be the day before.

How to mail a screen captured image using corona SDK

I am new to corona SDK, but I've managed to capture my app scene using the following code:
local function captureArea()
local myCaptureImage = display.captureBounds(display.currentStage.contentBounds, true)
myCaptureImage:removeSelf()
myCaptureImage = nil
end
bg:addEventListener("tap",captureArea)
This works perfectly.
Now I need to send the captured image(with a specific name, say: screen_1.png) to my friend via email. I've used Composing E-mail and SMS for refference, but I fail to understand how I can add this saved image in the attachment field of mail options.
Please give me a proper solution that how can I attach and send the above saved image via email.
display.captureBounds is good for saving the whole screen to the directory. But it usually saves the file with increase in last index. So it may be difficult to read them correctly. So I prefer display.save. But it is not a straight way.
For doing this, you have to:
First create a localgroup.
Then add the screen objects to that group.
Return the display group
Use display.save to save the entire group displayed.
Create mail option and add attachment image from baseDirectory
Call mail Popup
I am giving a sample here:
-- creating the display group --
local localGroup = display.newGroup()
-- creating display objects and adding it to the group --
local bg = display.newRect(0,0,_w,_h)
bg.x = 160
bg.y = 240
bg:setFillColor(150)
localGroup:insert(bg)
local rect = display.newRect(0,0,50,50)
rect.x = 30+math.random(260)
rect.y = 30+math.random(420)
localGroup:insert(rect)
-- Then do as follows --
local function takePhoto_andSendMail()
-- take screen shot to baseDirectory --
local baseDir = system.DocumentsDirectory
display.save( localGroup, "myScreenshot.jpg", baseDir )
-- Create mail options --
local options =
{
to = { "krishnarajsalim#gmail.com",},
subject = "My Level",
body = "Add this...",
attachment =
{
{ baseDir=system.DocumentsDirectory, filename="myScreenshot.jpg", type="image" },
},
}
-- Send mail --
native.showPopup("mail", options)
end
rect:addEventListener("tap",takePhoto_andSendMail)
This will do it...
Keep coding........ :)

Importing EML (MIME) files in Outlook programmatically

I have a directory full of email files I want to import into Outlook.
These files should be, AFAIK, in RFC822 format. Opening them with Notepad++ shows the following and more plaintext
Return-Path: XXX
Received: XXX
Authentication-Results: XXX
X-Message-Status: XXX
X-SID-PRA: XXX
X-SID-Result: XXX
X-AUTH-Result: XXX
X-Message-Delivery: XXX
X-Message-Info: XXXX
Received: from XXX
Received: from XXX
DomainKey-Signature: XXX
So I guess they are in plain old format. Now I would like to import them into a PST file in order to index and make them searcheable. I have very poor knowledge of Outlook Interop.
Renaming the untitled files to .eml works, I can open them with Outlook 2010. Dragging them into Outlook windows half works: emails are not previewed but I can double-click them. Not all emails get imported (I'm talking about 3000+ messages), and Outlook doesn't ingore damaged files, so either all or none.
I was exploring Outlook interop.
The basic idea is the following: for each text file, import that as email into a given folder.
I have tried to write, but not yet to test, the following code
Application outlook = GetApplicationObject();
outlook.Session.AddStore(pstPath);
Store theStore = outlook.Session.Stores.Cast<Store>().FirstOrDefault(store => store.FilePath == pstPath);
if (theStore == null) throw new Exception();
try
{
string[] files = Directory.GetFiles(dataDirectory, "*", SearchOption.AllDirectories);
Folder folder = (Folder)theStore.GetRootFolder();
foreach (string file in files.Where(file => file.EndsWith(".eml")))
{
//What?
}
}
finally
{
//Dispose??
}
Where GetApplicationObject is copied from another SO answer.
Question: is it possible to create a MailItem based on the contents of a file? Or do I have to use an email reader and then create the MailItem field by field? Like the following I was writing...
IMail mail = builder.CreateFromEmlFile(file);
MailItem outlookMail = outlook.CreateItem(OlItemType.olMailItem);
outlookMail.Body = mail.GetBodyAsText();
outlookMail.CC = string.Join("; ", mail.Cc.Select(x => x.Render()));
outlookMail.HTMLBody = mail.GetBodyAsHtml();
if (MimeImportance.High.Equals(mail.Importance))
outlookMail.Importance = OlImportance.olImportanceHigh;
else if (MimeImportance.Low.Equals(mail.Importance))
outlookMail.Importance = OlImportance.olImportanceLow;
else
outlookMail.Importance = OlImportance.olImportanceNormal;
outlookMail.Sender=outlook.CreateItem()
Library I'm trying is from http://www.limilabs.com/mail
If you were using C++ or Delphi, you could use the IConverterSession MAPI interface - you can play with it in OutlookSpy (I am its author) if you click the IConverterSession button.
Otherwise you can use Redemption (I am also its author) and its RDOMail object - its Import method supports MIME format (among a dozen or so other formats).
set Session = CreateObject("Redemption.RDOSession")
Session.MAPIOBJECT = Application.Session.MAPIOBJECT
set Inbox = Session.GetDefaultFolder(olFolderInbox)
set Msg = Inbox.Items.Add
Msg.Sent = true
Msg.Import "C:\Temp\test.eml", 1024
Msg.Save

DDay iCal w/ Non-DST Time Zones

I've posted to the forums for the DDay iCal library but thought to post it here in case any users have come across this situation. From my forum post:
I've come across what appears to be a bug in how the time zone section is generated in an iCal file- adding a time zone that does not support Daylight Saving Time creates an empty VTIMEZONE section, which breaks the iCal. A quick glance at the code leads me to believe that the section is generated by the collection returned by TimeZoneInfo.GetAdjustmentRules(), which is empty for time zones that do not observe DST.
The code at the bottom of the post should demonstrate this issue.
If this is not a bug (and I am not convinced that it is!), I'd very much appreciate guidance in getting these to work.
void Main()
{
foreach (var tz in TimeZoneInfo.GetSystemTimeZones())
{
var cal = GetCal(tz);
Console.WriteLine(tz.Id + " :: " + tz.SupportsDaylightSavingTime + " :: " + cal.TimeZones.First().ID);
}
}
iCalendar GetCal(TimeZoneInfo timeZone)
{
var calendar = new iCalendar();
calendar.AddChild(iCalTimeZone.FromSystemTimeZone(timeZone));
var #event = new Event
{
Name = "VEVENT",
DTStart = new iCalDateTime(DateTime.Now, timeZone.Id),
DTEnd = new iCalDateTime(DateTime.Now + TimeSpan.FromHours(1))
};
calendar.Events.Add(#event);
return calendar;
}
I pulled down the latest source from SVN and the fix for this has already been applied; it's just not in the latest release DLL as of 6/30/2011.

Date browsers problem - if manually changed and focus on it - did not save

I have a problem related to Date type which I'm using in smartgwt.
I set up the date to have the possibility to change it manually:
setAttribute("useTextField", true);
In Firefox and Chrome (and maybe other browsers , except Internet Explorer) if first I'm selecting a date with that pop-up calendar and than change it manually and then let the focus on the date field and going to save the document (actually is a form with multiple fields) the date changed manually it is lost, the date choosed from calendar it is saved. This is not happening in Internet Explorer.
In all browsers, if I select from Calendar a date and than change it manually and change the focus from it everythings goes fine - the manually changed date it is saved into db.
Need some advices.
Thank you a lot.
Later edit:
I'm using com.smartgwt.client.widgets.form.fields.DateItem widget.
DateItem date = new DateItem("A date");
date.setWidth(320);
date.setWrapTitle(false);
date.setAttribute("useTextField", true);
date.setAttribute("inputFormat", "yyyy/MM/dd");
date.setAttribute("displayFormat", "toJapanShortDate");
I'm adding this date on a DynamicForm:
DynamicForm form = new DynamicForm();
form.setFields(date);
and this form on a VLayout object:
VLayout editLayout = new VLayout(30);
editLayout.addMember(form);
The problem is reproducing in browsers like Firefox & Chrome when:
I'm selecting first the date from calendar - say I'm selecting 2011/02/11
I'm changing the day in 2011/02/12 manually - and I'm not changing the focus from this date field
I'm pressing the 'Save' button.
After these steps the date is 2011/02/11 and not 2011/02/12 how it should be.
In Internet Explorer browser did not happen - the date after the steps above is 2011/02/12!
Later edit:
I'm using a DataSource for updating the data.
I'm having a UserObject and in the userUpdate method I'm creating this user object first with values from fields (which are on the DynamicForm) - by calling the generateUserObjectFromForm() method
UserObject user = generateUserObjectFromForm();
Here, in this method I'm doing something like:
user.setAddedDate(date.getValueAsDate()),
but here the date.getValueAsDate() value is the one selected from calendar, not the one modified manually.
I've tried also with:
date.getValue() //Fri Feb 11 00:00:00 GMT+200 2011
date.getValueField() // null
date.getValueAsDate() //Fri Feb 11 00:00:00 GMT+200 2011
date.getDisplayField() //null
date.getDisplayValue()//l2011/02/11
but none worked properly.
I'm using an request object (UserUpdateRequest) for updating the user.
UserUpdateRequest looks like:
public class UserUpdateRequest implements IsSerializable
{
UserObject user = null;
public UserUpdateRequest ()
{
}
public UserUpdateRequest (UserObject user)
{
this.user = user;
}
public UserObject getUser ()
{
return user;
}
}
final UserUpdateRequest request = new UserUpdateRequest(user);
and on the RPC user update method I'm sending this UserUpdateRequest request.
Later edit (15 february):
I've discovered why is happening this issue related to focus, and this is because in the project I'm not using a Button object - and a com.google.gwt.event.dom.client.ClickEvent for it. I'm using a personalized widget:
package de.vogella.gwt.helloworld.client;
import com.smartgwt.client.widgets.Label;
public class buttonLabel extends Label
{
public buttonLabel (String text, String elementID)
{
super();
setContents(text);
setAutoWidth();
setBaseStyle("wwHoverLabel");
setShowRollOver(true);
}
}
and this use com.smartgwt.client.widgets.events.ClickHandler().
Anyway I do not know how to resolve this ....
I've created a small project with this issue where I've put also a Button object (Save1) and also a personalized button buttonLabel (Save2) - both with clickhandlers.
Here is the link where you can download sources of this small project I've created: link
Case1:
say for example we choose date 2011/02/16 and we change manually the date into 2011/02/17 and push the button Save1 - everything works fine - the date remains 2011/02/17
Case2-a - line
Window.alert("2 " + date.getValue()); un-commented:
say for example we choose date 2011/02/16 and we change manually the date into 2011/02/17 and push the button Save2 - in the warning message date value is 2011/02/16 but in the field date remains 2011/02/17
Case2-b - line
Window.alert("2 " + date.getValue()); uncommented:
say for example we choose date 2011/02/16 and we change manually the date into 2011/02/17 and push the button Save2 - the value from field date is automatically changed to 2011/02/16
Later later edit:
Since I can't figure out how to solve my problem I'm thinking for the moment at a temporary solution.
So, I have:
DateItem date = new DateItem("Adate");
date.setWidth(120);
date.setWrapTitle(false);
date.setAttribute("useTextField", true);
date.setAttribute("inputFormat", "yyyy/MM/dd");
date.setAttribute("displayFormat", "toJapanShortDate");
Because the attribute useTextField is set to true we can see the text entry field. How can I make this text entry field to be un-editable. Actually I want to have only the possibility to choose the date from calendar and not to change it manually.
The following code should work.
DateItem date = new DateItem("Adate");
date.setAttribute("useTextField", true);
date.setAttribute("inputFormat", "yyyy/MM/dd");
date.setAttribute("displayFormat", "toJapanShortDate");
TextItem textItem = new TextItem();
textItem.setAttribute("readOnly", "true");
date.setTextFieldProperties(textItem);