Normal Topic ICAL Files and @Newline() (Read 2970 times)
BWETTLAUFER
Full Member
***
Offline



Posts: 216
Location: Cambridge, Ontario
Joined: Apr 9th, 2010
ICAL Files and @Newline()
Feb 8th, 2018 at 9:22pm
Print Post Print Post  
Hi folks!

I'm making Sesame output ICS Calendar files through a mass update, and I'm almost there.  I can create a ICS file that is read by a desktop, but not a mobile device.

Working backwards from a working ICS file on my cell phone, it appears that @newline() creates a CRLF line break, where the mobile friendly file I can create uses LF ... so I tried replacing @newline() with @chr(10), which should have done it ... but no dice.  When I open the ICS file created, it's still coming up as CRLF.

Any suggestions?

Code
Select All
stat vFileName as string
stat vData as string
stat vSubject as string
stat vMessage as string
stat n as int
stat q as int

stat vStaffInfo as string
stat vDBID as string
stat vCallDate as date
stat vCallTime as string
stat vEndTime as string
stat vCallInvite as string
stat vContact as string
stat vSummary as string
stat vBody as string

vStaffInfo = @xlookupsourcelist(@FN,@userid,"Staff Screen!StaffRef","staffname;staffemail;staffext")
vCallDate = @promptForUserInput("Scheduled Call Date?",@serverdate())
vCallTime = @PromptForuserinput("Scheduled Call Time?",@servertime())
vCallInvite = @PromptForUserInput("Schedule For",@accessstringarray(vStaffInfo,2))
vContact = @PromptForUserInput("Person To Call",DBName)
vSummary = @PromptForUserInput("Subject of Calendar Reminder?","Scheduled Call"
vBody = @PromptForUserInput("Body of Calendar Invite?","We need to arrange to speak with you at your earliest convenience -- please accept this calendar invite or reschedule for a time you are available.  Please contact " + @accessstringarray(vStaffInfo,1) + " at " + @accessstringarray(vStaffInfo,3) + " or at " + @accessstringarray(vStaffInfo,2))

if vCallDate <> "" and vCallTime <> "" and vCallInvite <> ""
{
	vFileName = "S:\Data\RawData\" + DBID + "-" + @num(@serverdate()) + "-" +@num(@servertime()) + ".ics"

	vEndTime = @sum(@tonumber(@num(vCalltime)),15)

	FileDelete(vFileName)
	q = FileOpen(vFileName)
	FileSeek(q,0)

	vData =
	"BEGIN:VCALENDAR" + @chr(10) +
	"VERSION:2.0" + @chr(10) +
	"BEGIN:VEVENT" + @chr(10) +
	"DTSTART:" + @num(vCallDate) + "T" + @sum(@tonumber(@num(vCalltime)),0) + "00Z" + @chr(10) +
	"DTEND:" + @num(vCallDate) + "T" + vEndTime + "00Z" + @chr(10) +
	"SUMMARY:" + vSummary + @chr(10) +
	"DESCRIPTION:" + vBody + @chr(10) +
	"END:VEVENT" + @chr(10) +
	"END:VCALENDAR"

	Writeln(vData)

	FileWrite(q,vData)
	FileClose(q)

	n = @sendmail("mail.kingstondc.com",vSummary,@accessstringarray(vStaffInfo,2),vCallInvite,"","",vBody,"bwettlaufer@kingstondc.com","SECRETPASSWORD",vFileName)
}
Else
{
	@msgbox("Can't Schedule Call","Without A Time and Date","Try Again")
}
 


  
Back to top
IP Logged
 
Ray the Reaper
Global Moderator
Members
Lantica Support
*****
Offline


The One & The Only

Posts: 2482
Joined: Aug 20th, 2003
Re: ICAL Files and @Newline()
Reply #1 - Feb 8th, 2018 at 10:02pm
Print Post Print Post  
Where are you seeing the CRLF pairs, In the original ics file on your S drive or after the file has been emailed?

-Ray
  

Raymond Yoxall Consulting
ray.yoxall@gmail.com
ryoxall@lantica.com
Sesame Applications, Design and Support
Back to top
IP Logged
 
BWETTLAUFER
Full Member
***
Offline



Posts: 216
Location: Cambridge, Ontario
Joined: Apr 9th, 2010
Re: ICAL Files and @Newline()
Reply #2 - Feb 9th, 2018 at 12:58am
Print Post Print Post  
Good question ... in the output file saved locally, as well as the attached email file.  Here's a screen cap ...
  

CRLF-example.png ( 25 KB | 107 Downloads )
CRLF-example.png
Back to top
IP Logged
 
Ray the Reaper
Global Moderator
Members
Lantica Support
*****
Offline


The One & The Only

Posts: 2482
Joined: Aug 20th, 2003
Re: ICAL Files and @Newline()
Reply #3 - Feb 9th, 2018 at 3:37pm
Print Post Print Post  
It looks like Windows may be "Saving" you from creating an invalid newline sequence.... Sigh... Let me check with Mark to verify and one of us will get back to you.

-Ray
  

Raymond Yoxall Consulting
ray.yoxall@gmail.com
ryoxall@lantica.com
Sesame Applications, Design and Support
Back to top
IP Logged
 
Ray the Reaper
Global Moderator
Members
Lantica Support
*****
Offline


The One & The Only

Posts: 2482
Joined: Aug 20th, 2003
Re: ICAL Files and @Newline()
Reply #4 - Feb 9th, 2018 at 4:10pm
Print Post Print Post  
Yup, that's what is happening. FileOpen() is opening the file as a TEXT file so Windows is being helpful in making sure it's a proper Text file. The solution we came to would be to run it through an external program after it has been written to the hard drive. Something that would go through and remove the 13 chars. Or an external program that takes STDIO and writes it out to a BINARY File that could be called via RedirectProcess() and passed the data.

-Ray
  

Raymond Yoxall Consulting
ray.yoxall@gmail.com
ryoxall@lantica.com
Sesame Applications, Design and Support
Back to top
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: ICAL Files and @Newline()
Reply #5 - Feb 9th, 2018 at 5:50pm
Print Post Print Post  
Blair,

Ray is right. The issue is in the code inside FileOpen. It uses the operating system default options, which in the case of Windows is "text mode". It is as old as DOS, that Microsoft terminates lines in text files with the CRLF pair. They did this, oddly, to remain compatible with old teletype machines, while eschewing compatibility with earlier operating systems.

You may do as Ray suggests. We may be able to provide you with a program that can be invoked through RedirectProcess. You many also want to explore sending the email some other way. Currently, you are creating a text file to attach to an email. Can you simply include the text in the email, rather than attach it as a file? If not, can you attach text in the email without drawing it from an external file?
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: ICAL Files and @Newline()
Reply #6 - Feb 9th, 2018 at 6:12pm
Print Post Print Post  
I can't test this at the moment (I am out sick and have no Windows boxes handy), but you may be able to use filePos and fileSeek to back up one byte after each line is written. This will cause the next line to start on the very last byte of the previous line, over-writing the offending character.
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
Ray the Reaper
Global Moderator
Members
Lantica Support
*****
Offline


The One & The Only

Posts: 2482
Joined: Aug 20th, 2003
Re: ICAL Files and @Newline()
Reply #7 - Feb 9th, 2018 at 6:27pm
Print Post Print Post  
The Cow wrote on Feb 9th, 2018 at 6:12pm:
I can't test this at the moment (I am out sick and have no Windows boxes handy), but you may be able to use filePos and fileSeek to back up one byte after each line is written. This will cause the next line to start on the very last byte of the previous line, over-writing the offending character.


Wouldn't work. Backing up one byte would over write the 10 and leave the 13.

-Ray
  

Raymond Yoxall Consulting
ray.yoxall@gmail.com
ryoxall@lantica.com
Sesame Applications, Design and Support
Back to top
IP Logged
 
BWETTLAUFER
Full Member
***
Offline



Posts: 216
Location: Cambridge, Ontario
Joined: Apr 9th, 2010
Re: ICAL Files and @Newline()
Reply #8 - Feb 9th, 2018 at 7:23pm
Print Post Print Post  
Yeah, it needs to be an attachment -- I'm building an ICS file that is attached to the email for an external computer to read it as a calendar invite.  Inside the email it would just be gibberish.

An external program to strip out the CR would be great. 

Alternatively, is there a way inside Sesame to create an external file without the need for an external program?  Like a some sort of synch/shell process to take what I build as the contents and then create the external file?
  
Back to top
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: ICAL Files and @Newline()
Reply #9 - Feb 9th, 2018 at 7:47pm
Print Post Print Post  
BWETTLAUFER wrote on Feb 9th, 2018 at 7:23pm:
An external program to strip out the CR would be great. 

Alternatively, is there a way inside Sesame to create an external file without the need for an external program?  Like a some sort of synch/shell process to take what I build as the contents and then create the external file?


Your best bet is to use a small program that collects the string through standard I/O and writes a file using binary mode. You would invoke this in SBasic using RedirectProcess. It would save the file. The only issue I can see with this approach is that the program would need two pieces of information. It would need the filename and the string to save. I could write this program and send you the source and executable. Or, if you (or any of your folk) are familiar with any of the scripting languages you have installed (Perl, PHP, etc), the program itself is fairly trivial.

I am assuming the SBasic in question must run on Windows. If you can run it on Unix, there is no issue to address.
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged