2002-04-02 18:47:56 +00:00
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is OEone Calendar Code, released October 31st, 2001.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* OEone Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2001
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s): Dan Parent <danp@oeone.com>
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
var gMailAccounts = false;
|
2002-04-03 16:43:14 +00:00
|
|
|
var gMAILDEBUG = 1; // 0 - no output, 1 dump to terminal, > 1 use alerts
|
|
|
|
var gMailIdentity;
|
2002-04-02 18:47:56 +00:00
|
|
|
|
2002-09-11 18:27:09 +00:00
|
|
|
var emailStringBundle;
|
|
|
|
|
2002-04-12 20:24:10 +00:00
|
|
|
/**** checkForMailNews
|
2002-04-02 18:47:56 +00:00
|
|
|
*
|
|
|
|
* PURPOSE: if mailnews is installed return true, else false
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2002-04-12 20:24:10 +00:00
|
|
|
function checkForMailNews()
|
2002-04-02 18:47:56 +00:00
|
|
|
{
|
2002-09-11 18:27:09 +00:00
|
|
|
emailStringBundle = srGetStrBundle("chrome://calendar/locale/email.properties");
|
|
|
|
|
|
|
|
var AccountManagerComponent;
|
2002-04-02 18:47:56 +00:00
|
|
|
var AccountManagerService;
|
|
|
|
var AccountManager;
|
|
|
|
var DefaultAccount;
|
|
|
|
var SmtpServiceComponent;
|
|
|
|
var SmtpService;
|
|
|
|
var Smtp;
|
|
|
|
var DefaultSmtp;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
AccountManagerComponent = Components.classes["@mozilla.org/messenger/account-manager;1"];
|
|
|
|
AccountManagerService = AccountManagerComponent.getService();
|
|
|
|
}
|
|
|
|
catch(ex) // yikes no account manager == no accounts
|
|
|
|
{
|
|
|
|
// from bug 122651 - scenario 1
|
|
|
|
noMail();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
try
|
|
|
|
{
|
|
|
|
AccountManager = AccountManagerService.QueryInterface(Components.interfaces.nsIMsgAccountManager);
|
|
|
|
DefaultAccount = AccountManager.defaultAccount;
|
2002-04-03 16:43:14 +00:00
|
|
|
gMailIdentity = DefaultAccount.defaultIdentity; // we'll store the user's account info globally for now
|
2002-04-02 18:47:56 +00:00
|
|
|
}
|
|
|
|
catch(ex)
|
|
|
|
{
|
|
|
|
// from bug 122651 - scenario 2
|
|
|
|
noAccount();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
try
|
|
|
|
{
|
|
|
|
SmtpServiceComponent = Components.classes["@mozilla.org/messengercompose/smtp;1"];
|
|
|
|
SmtpService = SmtpServiceComponent.getService();
|
|
|
|
Smtp = SmtpService.QueryInterface(Components.interfaces.nsISmtpService);
|
|
|
|
DefaultSmtp = Smtp.defaultServer;
|
|
|
|
}
|
|
|
|
catch(ex)
|
|
|
|
{
|
|
|
|
// if we don't have an SMTP server to use I'm not going
|
|
|
|
// to allow mail features to be enabled for now
|
|
|
|
// from bug 122651: scenarios 3, and 6
|
|
|
|
noSmtp();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// if we get here that means we must have a default account and default smtp server otherwise
|
|
|
|
// the thrown exceptions would have been caught.
|
|
|
|
// from bug 122651 - scenarios 4, 5, 7, and 8
|
|
|
|
// we'll just use the default account for now.
|
|
|
|
gMailAccounts = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**** noMail
|
|
|
|
*
|
|
|
|
* PURPOSE: function to handle the scenario when mailnews is not installed
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
function noMail()
|
|
|
|
{
|
|
|
|
// maybe provide a way of telling the user how to get a mailnews build
|
|
|
|
// this should be a pref with a window that has a checkbox to shut off
|
|
|
|
// this warning (for people that don't want mailnews installed)
|
|
|
|
mdebug("You don't have mail installed");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**** noAccount
|
|
|
|
*
|
|
|
|
* PURPOSE: function to handle the scenario where mailnews is installed but
|
|
|
|
* an account has not been created
|
|
|
|
*/
|
|
|
|
|
|
|
|
function noAccount()
|
|
|
|
{
|
|
|
|
// this could call the account wizard I guess thats a later feature
|
|
|
|
mdebug("You don't have a mail account");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**** noSmtp
|
|
|
|
*
|
|
|
|
* PURPOSE: function to handle the scenario where mailnews is installed, has
|
|
|
|
* a default incoming account but does not have an smtp service
|
|
|
|
*
|
|
|
|
* XXX: can this happen?
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
function noSmtp()
|
|
|
|
{
|
|
|
|
/* I don't really know if its possible to create this scenario, I'm putting it here for
|
|
|
|
* the sake of completion so that I can say I've at least covered all possible scenarios
|
|
|
|
* from bug 122651
|
|
|
|
*/
|
|
|
|
mdebug("You don't have an smtp account");
|
|
|
|
}
|
|
|
|
|
2002-04-12 20:24:10 +00:00
|
|
|
/**** sendEvent
|
|
|
|
*
|
|
|
|
* PURPOSE: implement iMip :) - that is send out a calendar event both
|
|
|
|
* as an attachment of type text/calendar and as text/plain
|
|
|
|
*/
|
|
|
|
|
2002-04-03 16:43:14 +00:00
|
|
|
function sendEvent()
|
|
|
|
{
|
|
|
|
var Event;
|
2002-04-12 20:24:10 +00:00
|
|
|
var CalendarDataFilePath;
|
2002-04-03 16:43:14 +00:00
|
|
|
var nsIMsgCompFieldsComponent;
|
|
|
|
var nsIMsgCompFields;
|
|
|
|
var nsIMsgComposeParamsComponent;
|
|
|
|
var nsIMsgComposeParams;
|
|
|
|
var nsIMsgComposeServiceComponent;
|
|
|
|
var nsIMsgComposeService;
|
|
|
|
var nsIMsgCompFormat;
|
|
|
|
var nsIMsgCompType;
|
2002-04-12 20:24:10 +00:00
|
|
|
var nsIMsgAttachmentComponent;
|
|
|
|
var nsIMsgAttachment;
|
2002-04-03 16:43:14 +00:00
|
|
|
|
2002-07-26 15:15:14 +00:00
|
|
|
Event = gCalendarWindow.EventSelection.selectedEvents[0].clone();
|
2002-04-12 20:24:10 +00:00
|
|
|
CalendarDataFilePath = getCalendarDataFilePath();
|
|
|
|
if (! CalendarDataFilePath)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2002-04-03 16:43:14 +00:00
|
|
|
/* Want output like
|
|
|
|
* When: Thursday, November 09, 2000 11:00 PM-11:30 PM (GMT-08:00) Pacific Time
|
|
|
|
* (US & Canada); Tijuana.
|
|
|
|
* Where: San Francisco
|
|
|
|
* see bug 59630
|
|
|
|
*/
|
|
|
|
if (Event)
|
|
|
|
{
|
|
|
|
// lets open a composer with fields and body prefilled
|
|
|
|
try
|
|
|
|
{
|
2002-08-16 18:15:59 +00:00
|
|
|
Event.alarm = false;
|
|
|
|
|
|
|
|
if(Event.method == 0)
|
|
|
|
Event.method = Event.ICAL_METHOD_PUBLISH;
|
2002-04-12 20:24:10 +00:00
|
|
|
saveCalendarObject(CalendarDataFilePath, Event.getIcalString());
|
|
|
|
nsIMsgAttachmentComponent = Components.classes["@mozilla.org/messengercompose/attachment;1"];
|
|
|
|
nsIMsgAttachment = nsIMsgAttachmentComponent.createInstance(Components.interfaces.nsIMsgAttachment);
|
2002-09-11 18:27:09 +00:00
|
|
|
nsIMsgAttachment.name = emailStringBundle.GetStringFromName( "AttachmentName" );
|
2002-04-12 20:24:10 +00:00
|
|
|
nsIMsgAttachment.contentType = "text/calendar;"
|
|
|
|
nsIMsgAttachment.temporary = true;
|
|
|
|
nsIMsgAttachment.url = "file://" + CalendarDataFilePath;
|
2002-04-03 16:43:14 +00:00
|
|
|
// lets setup the fields for the message
|
|
|
|
nsIMsgCompFieldsComponent = Components.classes["@mozilla.org/messengercompose/composefields;1"];
|
|
|
|
nsIMsgCompFields = nsIMsgCompFieldsComponent.createInstance(Components.interfaces.nsIMsgCompFields);
|
2002-04-12 20:24:10 +00:00
|
|
|
nsIMsgCompFields.useMultipartAlternative = true;
|
|
|
|
nsIMsgCompFields.attachVCard = true;
|
2002-04-03 16:43:14 +00:00
|
|
|
nsIMsgCompFields.from = gMailIdentity.email;
|
|
|
|
nsIMsgCompFields.replyTo = gMailIdentity.replyTo;
|
2002-07-26 15:15:14 +00:00
|
|
|
nsIMsgCompFields.subject = Event.title;
|
2002-04-03 16:43:14 +00:00
|
|
|
nsIMsgCompFields.organization = gMailIdentity.organization;
|
2002-09-11 18:27:09 +00:00
|
|
|
nsIMsgCompFields.body = emailStringBundle.GetStringFromName( "When" )+" " + Event.start + "-" + Event.end + "\n"+emailStringBundle.GetStringFromName( "Where" )+" " + Event.location + "\n"+emailStringBundle.GetStringFromName( "Organizer" )+" " + gMailIdentity.fullName + " <" + gMailIdentity.email + ">" + "\n"+emailStringBundle.GetStringFromName( "Summary" )+":" + Event.description;
|
2002-04-12 20:24:10 +00:00
|
|
|
nsIMsgCompFields.addAttachment(nsIMsgAttachment);
|
2002-04-03 16:43:14 +00:00
|
|
|
/* later on we may be able to add:
|
|
|
|
* returnReceipt, attachVCard
|
|
|
|
*/
|
|
|
|
// time to handle the message paramaters
|
|
|
|
nsIMsgComposeParamsComponent = Components.classes["@mozilla.org/messengercompose/composeparams;1"];
|
|
|
|
nsIMsgComposeParams = nsIMsgComposeParamsComponent.createInstance(Components.interfaces.nsIMsgComposeParams);
|
|
|
|
nsIMsgComposeParams.composeFields = nsIMsgCompFields;
|
|
|
|
nsIMsgCompFormat = Components.interfaces.nsIMsgCompFormat;
|
|
|
|
nsIMsgCompType = Components.interfaces.nsIMsgCompType;
|
|
|
|
nsIMsgComposeParams.format = nsIMsgCompFormat.PlainText; // this could be a pref for the user
|
|
|
|
nsIMsgComposeParams.type = nsIMsgCompType.New;
|
|
|
|
// finally lets pop open a composer window after all this work :)
|
|
|
|
nsIMsgComposeServiceComponent = Components.classes["@mozilla.org/messengercompose;1"];
|
|
|
|
nsIMsgComposeService = nsIMsgComposeServiceComponent.getService().QueryInterface(Components.interfaces.nsIMsgComposeService);
|
|
|
|
nsIMsgComposeService.OpenComposeWindowWithParams(null, nsIMsgComposeParams);
|
|
|
|
}
|
|
|
|
catch(ex)
|
|
|
|
{
|
|
|
|
mdebug("failed to get composer window\nex: " + ex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-04-12 20:24:10 +00:00
|
|
|
/**** getCalendarDataFilePath
|
|
|
|
*
|
|
|
|
* PURPOSE: get the user's current profile directory and use it as a place
|
|
|
|
* to temporarily store the iCal tempfile that I need to attach
|
|
|
|
* to the email
|
|
|
|
*/
|
|
|
|
|
|
|
|
function getCalendarDataFilePath()
|
|
|
|
{
|
|
|
|
var FilePath;
|
|
|
|
var DirUtilsComponent;
|
|
|
|
var DirUtilsInstance;
|
|
|
|
var nsIFile;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
DirUtilsComponent = Components.classes["@mozilla.org/file/directory_service;1"];
|
|
|
|
DirUtilsInstance = DirUtilsComponent.createInstance(Components.interfaces.nsIProperties);
|
|
|
|
nsIFile = Components.interfaces.nsIFile;
|
|
|
|
FilePath = DirUtilsInstance.get("ProfD", nsIFile).path;
|
2002-07-05 18:41:18 +00:00
|
|
|
var aFile = Components.classes["@mozilla.org/file/local;1"].createInstance();
|
|
|
|
var aLocalFile = aFile.QueryInterface(Components.interfaces.nsILocalFile);
|
|
|
|
if (!aLocalFile) return false;
|
|
|
|
|
|
|
|
aLocalFile.initWithPath(FilePath);
|
|
|
|
aLocalFile.append( "tempIcal.ics" );
|
|
|
|
|
|
|
|
FilePath = aLocalFile.path;
|
2002-04-12 20:24:10 +00:00
|
|
|
}
|
|
|
|
catch(ex)
|
|
|
|
{
|
|
|
|
mdebug("No filepath has been found, ex:\n" + ex);
|
|
|
|
FilePath = null;
|
|
|
|
}
|
|
|
|
return(FilePath);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**** saveCalendarObject
|
|
|
|
*
|
|
|
|
* PURPOSE: open a tmp file and write Ical info to it, this has
|
|
|
|
* to be done until there is a way to pass an ical URL to
|
|
|
|
* the messenger attachment code
|
|
|
|
*/
|
|
|
|
|
|
|
|
function saveCalendarObject(FilePath, CalendarStream)
|
|
|
|
{
|
|
|
|
var LocalFileComponent;
|
|
|
|
var LocalFileInstance;
|
|
|
|
var FileChannelComponent;
|
|
|
|
var FileChannelInstance;
|
|
|
|
var FileTransportComponent;
|
|
|
|
var FileTransportService;
|
|
|
|
var FileTransport;
|
|
|
|
var FileOutput;
|
|
|
|
|
|
|
|
// need LocalFile, otherwise what are we going to write to?
|
|
|
|
LocalFileComponent = Components.classes["@mozilla.org/file/local;1"];
|
|
|
|
LocalFileInstance = LocalFileComponent.createInstance(Components.interfaces.nsILocalFile);
|
|
|
|
LocalFileInstance.initWithPath(FilePath);
|
|
|
|
if (!LocalFileInstance.exists())
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
LocalFileInstance.create(LocalFileInstance.NORMAL_FILE_TYPE, 0644);
|
|
|
|
}
|
|
|
|
catch(ex)
|
|
|
|
{
|
|
|
|
mdebug("Unable to create temporary iCal file");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// need nsIFileChannel for ioflags
|
|
|
|
FileChannelComponent = Components.classes["@mozilla.org/network/local-file-channel;1"];
|
|
|
|
FileChannelInstance = FileChannelComponent.createInstance(Components.interfaces.nsIFileChannel);
|
|
|
|
// need nsIFileTransport to create a transport
|
|
|
|
FileTransportComponent = Components.classes["@mozilla.org/network/file-transport-service;1"];
|
|
|
|
FileTransportService = FileTransportComponent.getService(Components.interfaces.nsIFileTransportService);
|
|
|
|
// need nsITransport to open an output stream
|
|
|
|
FileTransport = FileTransportService.createTransport(LocalFileInstance, FileChannelInstance.NS_RDWR, 0644, true);
|
|
|
|
// need nsIOutputStream to write out the actual file
|
|
|
|
FileOutput = FileTransport.openOutputStream(0, -1, null);
|
|
|
|
// now lets actually write the output to the file
|
|
|
|
FileOutput.write(CalendarStream, CalendarStream.length);
|
|
|
|
FileOutput.close();
|
|
|
|
}
|
|
|
|
|
2002-04-02 18:47:56 +00:00
|
|
|
/**** mdebug
|
|
|
|
*
|
|
|
|
* PURPOSE: display debugging messages
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
function mdebug(message)
|
|
|
|
{
|
|
|
|
if (gMAILDEBUG == 1)
|
|
|
|
{
|
|
|
|
dump(message + "\n");
|
|
|
|
}
|
|
|
|
else if (gMAILDEBUG > 1)
|
|
|
|
{
|
|
|
|
alert(message);
|
|
|
|
}
|
|
|
|
}
|