Back to index

lightning-sunbird  0.9+nobinonly
MailFrame.cpp
Go to the documentation of this file.
00001 /* ***** BEGIN LICENSE BLOCK *****
00002  * Version: Mozilla-sample-code 1.0
00003  *
00004  * Copyright (c) 2002 Netscape Communications Corporation and
00005  * other contributors
00006  *
00007  * Permission is hereby granted, free of charge, to any person obtaining a
00008  * copy of this Mozilla sample software and associated documentation files
00009  * (the "Software"), to deal in the Software without restriction, including
00010  * without limitation the rights to use, copy, modify, merge, publish,
00011  * distribute, sublicense, and/or sell copies of the Software, and to permit
00012  * persons to whom the Software is furnished to do so, subject to the
00013  * following conditions:
00014  *
00015  * The above copyright notice and this permission notice shall be included
00016  * in all copies or substantial portions of the Software.
00017  *
00018  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00019  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00020  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
00021  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00022  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
00023  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
00024  * DEALINGS IN THE SOFTWARE.
00025  *
00026  * Contributor(s):
00027  *   Adam Lock <adamlock@netscape.com>
00028  *
00029  * ***** END LICENSE BLOCK ***** */
00030 
00031 #include "global.h"
00032 
00033 #include "MailFrame.h"
00034 #include "GeckoProtocolHandler.h"
00035 #include "nsEmbedString.h"
00036 
00037 #include "nsIURI.h"
00038 
00039 struct MailMsg
00040 {
00041     char *mSubject;
00042     char *mSender;
00043     char *mDate;
00044     char *mBody;
00045 };
00046 
00047 MailMsg gSampleMessages[] = 
00048 {
00049     {
00050         "URGENT ASSITANCE PLS",
00051         "alexander nene",
00052         "09/06/2003 14:38",
00053         "<html><body>"
00054         "<p>Attention: Sir,<br>\n"
00055         "<p>Good day. I am ALEXANDER NENE, Solicitor and Notary Public, The Personal Attorney"
00056         "to MR HENRI CARLTON, The president of DIAMOND SAFARIESCO.LTD.ACCRA-GHANA who is a"
00057         "National of your country. On the 21st of April 2000, my client, his wife and their "
00058         "only son were Involved in a car accident along ACCRA/KUMASI Express Road."
00059         "<p>Unfortunately, they all lost their lives in the event of the accident, since then "
00060         "I have made several enquiries to locate any of my clients extended relatives and"
00061         "this has also proved unsuccessful.After these several unsuccessful attempts, I decided"
00062         "to trace his Relatives over the Internet, to locate any member of his family but of"
00063         "no avail, hence I contacted youI contacted you to assist in repatriating the money and"
00064         "property left Behind before they get confiscated or declare unserviceable by the bank"
00065         "where my client lodged this huge deposits. Particularly, the Bank where the deceased had"
00066         "an account valued at about 28.3 million dollars.Conseqently, the bank issued me a notice "
00067         "to provide the next of kin or Have the account confiscated within a short time. Since "
00068         "I have been Unsuccessful in locating the relatives for over some years now, I seek your "
00069         "consent to present you as the next of kin of the deceased since you share the same surname "
00070         "so that the proceeds of this account valued at 48.3 million dollars can be paid to you "
00071         "for both of us to share the money; 70% to me and 25% to you, while 5% should be for "
00072         "expenses or tax as your government may require. I have all necessary legal documents that"
00073         "can be used to backup the claim.All I require is your honest cooperation to enable us see"
00074         "this deal Through. "
00075         "<p>I guarantee that this will be executed under a legitimate arrangement"
00076         "that will protect you from any breach of the law. Please get in touch with me through my"
00077         "email to enable us discuss further.<br><br> \n"
00078         "<p>Thanks for you kind co-operation<br><br> \n"
00079         "<p>ALEXANDER NENE<br><br><br></body></html>"
00080     },
00081     {
00082         "Reminder: Network Outage Tonight",
00083         "IT Dept",
00084         "09/06/2003 15:22",
00085         "<html><body>The network will be going down tonight so please log off "
00086         "your computers before going home.</body></html>"
00087     },
00088     {
00089         "Expense Reports Due",
00090         "Finance Dept",
00091         "09/06/2003 15:40",
00092         "<html><body>Please submit expense reports ASAP if you want to see payment "
00093         "in your accounts this month!</body></html>"
00094     },
00095     {
00096         "Flight confirmation",
00097         "Expediocity",
00098         "12/06/2003 12:31",
00099         "<html><body>Thank you for booking with Expediocity, Your flight reservation has been "
00100         "confirmed and details may be found online <a href=\"http://www.mozilla.org\">here</a>.</body></html>"
00101     }
00102 };
00103 
00104 static bool gMailChannelCallbackRegistered = FALSE;
00105 
00106 class MailChannelCallback : public GeckoChannelCallback
00107 {
00108 public:
00109     virtual nsresult GetData(
00110         nsIURI *aURI,
00111         nsIChannel *aChannel,
00112         nsACString &aContentType,
00113         void **aData,
00114         PRUint32 *aSize)
00115     {
00116         nsCAutoString txt;
00117         aContentType.Assign("text/html");
00118 
00119         nsCAutoString path;
00120         aURI->GetPath(path);
00121 
00122         long i;
00123         if (sscanf(path.get(), "//%ld", &i) == 1)
00124         {
00125             txt = gSampleMessages[i].mBody;
00126         }
00127         else
00128         {
00129             return NS_ERROR_FAILURE;
00130         }
00131 
00132         size_t size = txt.Length();
00133         *aData = (void *) nsMemory::Alloc(size + 1);
00134         if (!*aData)
00135             return NS_ERROR_OUT_OF_MEMORY;
00136         memset(*aData, 0, size + 1);
00137         memcpy(*aData, txt.get(), size);
00138         *aSize = size;
00139         return NS_OK;
00140     }
00141 };
00142 
00143 BEGIN_EVENT_TABLE(MailFrame, GeckoFrame)
00144     EVT_LIST_ITEM_SELECTED(XRCID("articles"), MailFrame::OnArticleClick)
00145 END_EVENT_TABLE()
00146 
00147 MailFrame::MailFrame(wxWindow* aParent)
00148 {
00149     wxXmlResource::Get()->LoadFrame(this, aParent, wxT("mail_frame"));
00150 
00151     SetName("mail");
00152 
00153     SetIcon(wxICON(appicon));
00154 
00155     if (!gMailChannelCallbackRegistered)
00156     {
00157         GeckoProtocolHandler::RegisterHandler("wxmail", "wxMail handler", new MailChannelCallback);
00158         gMailChannelCallbackRegistered = TRUE;
00159     }
00160 
00161     // Set up the article pane
00162     wxListCtrl *articleListCtrl = (wxListCtrl *) FindWindowById(XRCID("articles"), this);
00163     if (articleListCtrl)
00164     {
00165         articleListCtrl->InsertColumn(0, "Subject", wxLIST_FORMAT_LEFT, 200);
00166         articleListCtrl->InsertColumn(1, "Sender", wxLIST_FORMAT_LEFT, 100);
00167         articleListCtrl->InsertColumn(2, "Date", wxLIST_FORMAT_LEFT, 100);
00168 
00169         for (long i = 0; i < sizeof(gSampleMessages) / sizeof(gSampleMessages[0]); i++)
00170         {
00171             articleListCtrl->InsertItem(i, gSampleMessages[i].mSubject);
00172             articleListCtrl->SetItem(i, 1, gSampleMessages[i].mSender);
00173             articleListCtrl->SetItem(i, 2, gSampleMessages[i].mDate);
00174         }
00175     }
00176 
00177     SetupDefaultGeckoWindow();
00178 
00179     wxWindow *hdrPanel = FindWindowById(XRCID("mail_header_panel"), this);
00180     if (hdrPanel)
00181     {
00182         hdrPanel->Show(FALSE);
00183     }
00184 
00185 
00186     CreateStatusBar();
00187 }
00188 
00189 void MailFrame::OnArticleClick(wxListEvent &event)
00190 {
00191     if (mWebBrowser)
00192     {
00193         long idx = event.GetIndex();
00194         wxString url = wxString::Format("wxmail://%ld", idx);
00195         if (!url.IsEmpty())
00196         {
00197             wxStaticText *txtFrom = (wxStaticText *) FindWindowById(XRCID("mail_from"), this);
00198             if (txtFrom)
00199                 txtFrom->SetLabel(gSampleMessages[idx].mSender);
00200             wxStaticText *txtDate = (wxStaticText *) FindWindowById(XRCID("mail_date"), this);
00201             if (txtDate)
00202                 txtDate->SetLabel(gSampleMessages[idx].mDate);
00203             wxStaticText *txtSubject = (wxStaticText *) FindWindowById(XRCID("mail_subject"), this);
00204             if (txtSubject)
00205                 txtSubject->SetLabel(gSampleMessages[idx].mSubject);
00206 
00207             wxWindow *hdrPanel = FindWindowById(XRCID("mail_header_panel"), this);
00208             if (hdrPanel)
00209                 hdrPanel->Show(TRUE);
00210 
00211             nsCOMPtr<nsIWebNavigation> webNav = do_QueryInterface(mWebBrowser);
00212             webNav->LoadURI(NS_ConvertASCIItoUCS2(url.c_str()).get(),
00213                                    nsIWebNavigation::LOAD_FLAGS_NONE,
00214                                    nsnull,
00215                                    nsnull,
00216                                    nsnull);
00217         }
00218     }
00219 }
00220