📄 imapfolderc.c
字号:
/* * $Id: ImapFolderC.C,v 1.12 2000/12/31 14:36:02 evgeny Exp $ * * Copyright (c) 1994 HAL Computer Systems International, Ltd. * * HAL COMPUTER SYSTEMS INTERNATIONAL, LTD. * 1315 Dell Avenue * Campbell, CA 95008 * * Author: Greg Hilton * Contributors: Tom Lang, Frank Bieser, and others * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * http://www.gnu.org/copyleft/gpl.html * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */#include <config.h>#include "ImapFolderC.h"#include "ImapServerC.h"#include "ImapMsgC.h"#include "FileMisc.h"#include "IshAppC.h"#include "AppPrefC.h"#include "MainWinC.h"#include "UndelWinC.h"#include "SortMgrC.h"#include "ImapMisc.h"#include "MsgListC.h"#include "MsgItemC.h"#include <hgl/RegexC.h>#include <hgl/CharC.h>#include <hgl/StringListC.h>#include <hgl/VBoxC.h>#include <time.h>/*------------------------------------------------------------------------ * ImapFolderC constructor */ImapFolderC::ImapFolderC(const char *n, Boolean create): FolderC(n, IMAP_FOLDER, create){ server = NULL; opened = False; long serverPort; StringC userName; Boolean imaps;//// Get server name and folder name etc// StringC folderName; if ( !ParseImapName(name, serverName, &serverPort, &imaps, userName, folderName) ) { return; } if ( isInBox ) { name = "INBOX"; } else { name = folderName; }//// Connect to the server// server = FindImapServer(serverName, serverPort, imaps, userName); if ( !server || !server->authenticated ) return; if ( !server->Exists(name) ) { // Create the folder if necessary (but we can't try to create INBOX) if ( !isInBox && create ) { StringListC output; if ( !server->Create(name, output) ) return; // Check response u_int count = output.size(); int i; for (i=0; i<count; i++) { CharC resp = *output[i]; if ( resp.StartsWith("NO ") ) return; } } else { return; } } opened = True;} // End ImapFolderC constructor/*------------------------------------------------------------------------ * ImapFolderC destructor */ImapFolderC::~ImapFolderC(){ if ( delFiles && server ) { StringListC output; server->Delete(name, output); }}/*------------------------------------------------------------------------ * Method to build message list */BooleanImapFolderC::Scan(){ if ( !server || !server->authenticated ) return False; time_t timeIn = 0; if ( debuglev > 0 ) { cout <<"Entering ImapFolderC(" <<BaseName(name) <<")::Scan" <<endl; timeIn = time(0); }//// Select the folder// msgCount = 0; //int newCount = 0; StringListC output; if ( !server->Select(name, output) ) return False; scanned = True;//// Read SELECT responses// u_int count = output.size(); int i=0; for (i=0; i<count; i++) { CharC resp = *output[i]; if ( resp.StartsWith("* ") ) { resp.CutBeg(2); resp.Trim(); } if ( resp.StartsWith("FLAGS", IGNORE_CASE) || resp.StartsWith("NO", IGNORE_CASE) ) ; else if ( resp.EndsWith("EXISTS", IGNORE_CASE) ) { resp.CutEnd(6); resp.Trim(); StringC num = resp; msgCount = atoi(num); } else if ( resp.EndsWith("RECENT", IGNORE_CASE) ) { resp.CutEnd(6); resp.Trim(); StringC num = resp; //newCount = atoi(num); } else if ( resp.StartsWith("OK", IGNORE_CASE) ) { resp.CutBeg(2); resp.Trim(); if ( resp.Contains("IGNORING DUPLICATE", IGNORE_CASE) ) { if ( debuglev > 0 ) { cout << "Enabling IMAP_BUG_DUPLICATE_SELECT workaround" <<endl; } server->bugs |= IMAP_BUG_DUPLICATE_SELECT; // Now, as the bug workaround has been enabled, // enter the same function again return Scan(); } writable = !resp.Contains("[READ-ONLY]", IGNORE_CASE); } else { server->Unexpected(resp); } } // End for each reply StringC statusStr;#if 0 Boolean showCount = (ishApp->mainWin->IsShown() && !ishApp->mainWin->IsIconified());#else//// This change was made to make the message status information show// up while the folder is being opened at start-up time. There ought to// be a better way...// Boolean showCount = True;#endif//// Get message information// fetchNeeded = True; for (i=0; i<msgCount; i++) {//// Update progress message if necessary// if ( showCount ) { statusStr = abbrev; statusStr += " - Scanning messages: "; statusStr += (int)msgList->size() + 1; ishApp->mainWin->Message(statusStr); }//// Add a message to the list// ImapMsgC *msg = new ImapMsgC(this, server, i+1); msgList->add(msg); }//// Update progress message if necessary// if ( showCount ) { statusStr = abbrev; statusStr += " - Scanning messages: "; statusStr += (int)msgList->size(); ishApp->mainWin->Message(statusStr); }//// Clean up// server->FetchFlush( fetchTag ); SetChanged(False); UpdateIcon(); ishApp->mainWin->ClearMessage(); if ( debuglev > 0 ) { time_t timeOut = time(0); cout <<"Leaving ImapFolderC(" <<BaseName(name) <<")::Scan after " <<(timeOut-timeIn) <<" seconds" <<endl; } return True;} // End Scan/*------------------------------------------------------------------------ * Method to save the folder. Used to get rid of deleted messages and * renumber remaining ones. */BooleanImapFolderC::Save(){ if ( !server || !server->authenticated ) return False; StringListC output; StringC saveFolder; if ( server->folder != name ) { saveFolder = server->folder; if ( !server->Select(name, output) ) return False; } if ( !server->Expunge(output) ) return False;//// Remove deleted messages from display// if ( active && !ishApp->exiting ) { ishApp->mainWin->MsgVBox().RemoveItems(*delItemList); if ( ishApp->undelWin ) ishApp->undelWin->Clear(); }//// Loop through message list and remove any deleted messages// u_int count = msgList->size(); u_int number = 1; int i=0; for (i=0; i<count; i++) { ImapMsgC *msg = (ImapMsgC*)(*msgList)[i]; if ( msg->IsDeleted() ) { delete msg; msgList->replace(NULL, i); } else { msg->SetNumber(number); number++; if ( msg->IsNew() && ishApp->appPrefs->markNewAsUnread ) msg->ClearNew(); } } // End for each message msgList->removeNulls(); delItemList->removeAll();//// Update display// if ( active && !ishApp->exiting ) { if ( SortMgr()->Threaded() ) ishApp->mainWin->MsgVBox().Sort(); ishApp->mainWin->MsgVBox().Refresh(); } if ( saveFolder.size() > 0 ) { if ( !server->Select(saveFolder, output) ) return False; } SetChanged(False); UpdateIcon(); return True;} // End Save/*------------------------------------------------------------------------ * Method to check for new mail */BooleanImapFolderC::NewMail(){ if ( !server || !server->authenticated ) return False; StringC saveFolder; if ( server->folder != name ) { saveFolder = server->folder; StringListC output; if ( !server->Select(name, output) ) return False; } int newCount = 0; Boolean newMail = False;//// Send NOOP command// StringListC output; output.AllowDuplicates(True); server->Noop(output); u_int count = output.size(); msgCount = msgList->size(); u_int numExpunges = 0; Boolean updateTitle = False; int i=0; for (i=0; i<count; i++) { CharC resp = *output[i]; if ( resp.StartsWith("* ") ) { resp.CutBeg(2);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -