PageMailPop3.cpp
资源名称:Netmanag.zip [点击查看]
上传用户:geanq888
上传日期:2007-01-03
资源大小:316k
文件大小:8k
源码类别:
Ftp客户端
开发平台:
Visual C++
- // PageMailPop3.cpp : implementation file
- //
- #include "stdafx.h"
- #include "netmanager.h"
- #include "PageMailPop3.h"
- #include "PageMailAccount.h"
- #include "GlobalsExtern.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CPageMailPop3 property page
- IMPLEMENT_DYNCREATE(CPageMailPop3, CPropertyPage)
- CPageMailPop3::CPageMailPop3() : CPropertyPage(CPageMailPop3::IDD)
- {
- //{{AFX_DATA_INIT(CPageMailPop3)
- //}}AFX_DATA_INIT
- }
- CPageMailPop3::~CPageMailPop3()
- {
- }
- void CPageMailPop3::DoDataExchange(CDataExchange* pDX)
- {
- CPropertyPage::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CPageMailPop3)
- DDX_Control(pDX, IDC_SERVERS, m_Servers);
- DDX_Control(pDX, IDC_MAILS, m_Mails);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CPageMailPop3, CPropertyPage)
- //{{AFX_MSG_MAP(CPageMailPop3)
- ON_BN_CLICKED(IDC_ADD, OnAdd)
- ON_BN_CLICKED(IDC_EDIT, OnEdit)
- ON_BN_CLICKED(IDC_REMOVE, OnRemove)
- ON_BN_CLICKED(IDC_GETMAIL, OnGetmail)
- ON_BN_CLICKED(IDC_DELETE, OnDelete)
- ON_BN_CLICKED(IDC_VIEW, OnView)
- ON_NOTIFY(NM_DBLCLK, IDC_SERVERS, OnDblclkServers)
- ON_BN_CLICKED(IDC_POP3_SAVE, OnPop3Save)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CPageMailPop3 message handlers
- BOOL CPageMailPop3::OnInitDialog()
- {
- CPropertyPage::OnInitDialog();
- m_ToolTip.Create(this);
- m_ToolTip.Activate(TRUE);
- CWnd* pWnd = GetWindow(GW_CHILD);
- while(pWnd)
- {
- int nID = pWnd->GetDlgCtrlID();
- if (nID != -1)
- m_ToolTip.AddTool(pWnd, pWnd->GetDlgCtrlID());
- pWnd = pWnd->GetWindow(GW_HWNDNEXT);
- }
- m_Servers.InsertColumn(0, _T("Server"));
- m_Servers.SetColumnWidth(0, 100);
- m_Servers.InsertColumn(1, _T("Username"));
- m_Servers.SetColumnWidth(1, 100);
- m_Mails.InsertColumn(0, _T("Server"));
- m_Mails.SetColumnWidth(0, 50);
- m_Mails.InsertColumn(1, _T("From"));
- m_Mails.SetColumnWidth(1, 100);
- m_Mails.InsertColumn(2, _T("Subject"));
- m_Mails.SetColumnWidth(2, 100);
- m_Mails.InsertColumn(3, _T("Date"));
- m_Mails.SetColumnWidth(3, 100);
- return TRUE; // return TRUE unless you set the focus to a control
- // EXCEPTION: OCX Property Pages should return FALSE
- }
- /////////////////////////////////////////////////////////////////////////////
- void CPageMailPop3::OnAdd()
- {
- CPageMailAccount dlg;
- if(dlg.DoModal() == IDOK)
- {
- int nItem = m_Servers.GetItemCount();
- m_Servers.InsertItem(nItem, LPCTSTR(dlg.m_sServer));
- m_Servers.SetItemText(nItem, 1, LPCTSTR(dlg.m_sUsername));
- ACCOUNT account;
- account.sServer = dlg.m_sServer;
- account.nPort = dlg.m_nPort;
- account.sUsername = dlg.m_sUsername;
- account.sPassword = dlg.m_sPassword;
- m_aAccounts.Add(account);
- }
- }
- /////////////////////////////////////////////////////////////////////////////
- void CPageMailPop3::OnEdit()
- {
- CPageMailAccount dlg;
- int nItem = -1;
- while((nItem = m_Servers.GetNextItem(nItem, LVNI_SELECTED)) != -1 )
- {
- dlg.m_sServer = m_aAccounts[nItem].sServer;
- dlg.m_nPort = m_aAccounts[nItem].nPort;
- dlg.m_sUsername = m_aAccounts[nItem].sUsername;
- dlg.m_sPassword = m_aAccounts[nItem].sPassword;
- if(dlg.DoModal() == IDOK)
- {
- m_Servers.SetItemText(nItem, 0, LPCTSTR(dlg.m_sServer));
- m_Servers.SetItemText(nItem, 1, LPCTSTR(dlg.m_sUsername));
- ACCOUNT account;
- account.sServer = dlg.m_sServer;
- account.nPort = dlg.m_nPort;
- account.sUsername = dlg.m_sUsername;
- account.sPassword = dlg.m_sPassword;
- m_aAccounts.SetAt(nItem, account);
- }
- }
- }
- /////////////////////////////////////////////////////////////////////////////
- void CPageMailPop3::OnRemove()
- {
- if(MessageBox("Really remove?", NULL, MB_ICONQUESTION | MB_YESNO) != IDNO)
- {
- int nItem = -1;
- while((nItem = m_Servers.GetNextItem(nItem, LVNI_SELECTED)) != -1)
- {
- m_Servers.DeleteItem(nItem);
- m_aAccounts.RemoveAt(nItem);
- nItem = -1;
- }
- }
- }
- /////////////////////////////////////////////////////////////////////////////
- void CPageMailPop3::OnDblclkServers(NMHDR* pNMHDR, LRESULT* pResult)
- {
- OnGetmail();
- *pResult = 0;
- }
- /////////////////////////////////////////////////////////////////////////////
- void CPageMailPop3::OnGetmail()
- {
- int nItem = -1;
- while((nItem = m_Mails.GetNextItem(nItem, LVNI_SELECTED)) != -1)
- {
- m_Pop.SetHost(m_aAccounts[nItem].sServer);
- m_Pop.SetPort(m_aAccounts[nItem].nPort);
- m_Pop.SetUser(m_aAccounts[nItem].sUsername);
- m_Pop.SetPassword(m_aAccounts[nItem].sPassword);
- if(!m_Pop.Connect())
- {
- AfxMessageBox(m_Pop.GetErrorMessage());
- return;
- }
- if(!m_Pop.Statistics())
- {
- AfxMessageBox(m_Pop.GetErrorMessage());
- return;
- }
- m_Mails.DeleteAllItems();
- UINT nMailNum = m_Pop.GetNumberOfMails();
- for(UINT nItem = 0; nItem < nMailNum; nItem++)
- {
- m_Mails.InsertItem(nItem, "From");
- m_Mails.SetItemText(nItem, 1, "Subject");
- }
- break;
- }
- }
- /////////////////////////////////////////////////////////////////////////////
- void CPageMailPop3::OnDelete()
- {
- if(MessageBox("Really delete?", NULL, MB_ICONQUESTION | MB_YESNO) != IDNO)
- {
- int nItem = -1;
- while((nItem = m_Mails.GetNextItem(nItem, LVNI_SELECTED)) != -1)
- {
- if(!m_Pop.Delete(nItem + 1))
- AfxMessageBox(m_Pop.GetErrorMessage());
- else
- m_Mails.DeleteItem(nItem);
- nItem = -1;
- }
- }
- }
- /////////////////////////////////////////////////////////////////////////////
- void CPageMailPop3::OnView()
- {
- int nItem = -1;
- while((nItem = m_Mails.GetNextItem(nItem, LVNI_SELECTED)) != -1)
- {
- if(m_Pop.Retrieve(nItem + 1))
- {
- g_WriteToOutput(TRUE, m_Pop.GetMsgContents());
- }
- else
- AfxMessageBox(m_Pop.GetErrorMessage());
- }
- }
- /////////////////////////////////////////////////////////////////////////////
- void CPageMailPop3::OnPop3Save()
- {
- int nItem = -1;
- while((nItem = m_Mails.GetNextItem(nItem, LVNI_SELECTED)) != -1 )
- {
- CFileDialog dlg(FALSE, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT);
- if(dlg.DoModal() == IDOK)
- {
- CString sPath = dlg.GetPathName();
- if(m_Pop.Retrieve(nItem + 1, sPath)) // Getting any particular mail message to file
- g_WriteToOutput(TRUE, "[Pop3] Message saved to file " + sPath);
- else
- AfxMessageBox(m_Pop.GetErrorMessage());
- }
- }
- }
- /////////////////////////////////////////////////////////////////////////////
- void CPageMailPop3::Serialize(CArchive& ar)
- {
- CString sItem;
- if (ar.IsStoring())
- { // storing code
- int j = m_aAccounts.GetSize();
- ar << j;
- for(int i = 0; i < j; i++)
- {
- ar << m_aAccounts[i].sServer;
- ar << m_aAccounts[i].nPort;
- ar << m_aAccounts[i].sUsername;
- ar << m_aAccounts[i].sPassword;
- }
- }
- else
- { // loading code
- ACCOUNT account;
- int j;
- ar >> j;
- j = atoi((LPCTSTR)sItem);
- for(int i = 0; i < j; i++)
- {
- ar >> account.sServer;
- ar >> account.nPort;
- ar >> account.sUsername;
- ar >> account.sPassword;
- m_aAccounts.Add(account);
- m_Servers.InsertItem(i, m_aAccounts[i].sServer);
- m_Servers.SetItemText(i, 1, m_aAccounts[i].sUsername);
- }
- }
- }
- /////////////////////////////////////////////////////////////////////////////
- BOOL CPageMailPop3::PreTranslateMessage(MSG* pMsg)
- {
- // transate the message based on TTM_WINDOWFROMPOINT
- MSG msg = *pMsg;
- msg.hwnd = (HWND)m_ToolTip.SendMessage(TTM_WINDOWFROMPOINT, 0, (LPARAM)&msg.pt);
- CPoint pt = pMsg->pt;
- if (msg.message >= WM_MOUSEFIRST && msg.message <= WM_MOUSELAST)
- ::ScreenToClient(msg.hwnd, &pt);
- msg.lParam = MAKELONG(pt.x, pt.y);
- // Let the ToolTip process this message.
- m_ToolTip.RelayEvent(&msg);
- return CPropertyPage::PreTranslateMessage(pMsg);
- }
- /////////////////////////////////////////////////////////////////////////////