Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/ShExBy/shex_roo.../lib64/python2....
File: mhlib.py
"""MH interface -- purely object-oriented (well, almost)
[0] Fix | Delete
[1] Fix | Delete
Executive summary:
[2] Fix | Delete
[3] Fix | Delete
import mhlib
[4] Fix | Delete
[5] Fix | Delete
mh = mhlib.MH() # use default mailbox directory and profile
[6] Fix | Delete
mh = mhlib.MH(mailbox) # override mailbox location (default from profile)
[7] Fix | Delete
mh = mhlib.MH(mailbox, profile) # override mailbox and profile
[8] Fix | Delete
[9] Fix | Delete
mh.error(format, ...) # print error message -- can be overridden
[10] Fix | Delete
s = mh.getprofile(key) # profile entry (None if not set)
[11] Fix | Delete
path = mh.getpath() # mailbox pathname
[12] Fix | Delete
name = mh.getcontext() # name of current folder
[13] Fix | Delete
mh.setcontext(name) # set name of current folder
[14] Fix | Delete
[15] Fix | Delete
list = mh.listfolders() # names of top-level folders
[16] Fix | Delete
list = mh.listallfolders() # names of all folders, including subfolders
[17] Fix | Delete
list = mh.listsubfolders(name) # direct subfolders of given folder
[18] Fix | Delete
list = mh.listallsubfolders(name) # all subfolders of given folder
[19] Fix | Delete
[20] Fix | Delete
mh.makefolder(name) # create new folder
[21] Fix | Delete
mh.deletefolder(name) # delete folder -- must have no subfolders
[22] Fix | Delete
[23] Fix | Delete
f = mh.openfolder(name) # new open folder object
[24] Fix | Delete
[25] Fix | Delete
f.error(format, ...) # same as mh.error(format, ...)
[26] Fix | Delete
path = f.getfullname() # folder's full pathname
[27] Fix | Delete
path = f.getsequencesfilename() # full pathname of folder's sequences file
[28] Fix | Delete
path = f.getmessagefilename(n) # full pathname of message n in folder
[29] Fix | Delete
[30] Fix | Delete
list = f.listmessages() # list of messages in folder (as numbers)
[31] Fix | Delete
n = f.getcurrent() # get current message
[32] Fix | Delete
f.setcurrent(n) # set current message
[33] Fix | Delete
list = f.parsesequence(seq) # parse msgs syntax into list of messages
[34] Fix | Delete
n = f.getlast() # get last message (0 if no messagse)
[35] Fix | Delete
f.setlast(n) # set last message (internal use only)
[36] Fix | Delete
[37] Fix | Delete
dict = f.getsequences() # dictionary of sequences in folder {name: list}
[38] Fix | Delete
f.putsequences(dict) # write sequences back to folder
[39] Fix | Delete
[40] Fix | Delete
f.createmessage(n, fp) # add message from file f as number n
[41] Fix | Delete
f.removemessages(list) # remove messages in list from folder
[42] Fix | Delete
f.refilemessages(list, tofolder) # move messages in list to other folder
[43] Fix | Delete
f.movemessage(n, tofolder, ton) # move one message to a given destination
[44] Fix | Delete
f.copymessage(n, tofolder, ton) # copy one message to a given destination
[45] Fix | Delete
[46] Fix | Delete
m = f.openmessage(n) # new open message object (costs a file descriptor)
[47] Fix | Delete
m is a derived class of mimetools.Message(rfc822.Message), with:
[48] Fix | Delete
s = m.getheadertext() # text of message's headers
[49] Fix | Delete
s = m.getheadertext(pred) # text of message's headers, filtered by pred
[50] Fix | Delete
s = m.getbodytext() # text of message's body, decoded
[51] Fix | Delete
s = m.getbodytext(0) # text of message's body, not decoded
[52] Fix | Delete
"""
[53] Fix | Delete
from warnings import warnpy3k
[54] Fix | Delete
warnpy3k("the mhlib module has been removed in Python 3.0; use the mailbox "
[55] Fix | Delete
"module instead", stacklevel=2)
[56] Fix | Delete
del warnpy3k
[57] Fix | Delete
[58] Fix | Delete
# XXX To do, functionality:
[59] Fix | Delete
# - annotate messages
[60] Fix | Delete
# - send messages
[61] Fix | Delete
#
[62] Fix | Delete
# XXX To do, organization:
[63] Fix | Delete
# - move IntSet to separate file
[64] Fix | Delete
# - move most Message functionality to module mimetools
[65] Fix | Delete
[66] Fix | Delete
[67] Fix | Delete
# Customizable defaults
[68] Fix | Delete
[69] Fix | Delete
MH_PROFILE = '~/.mh_profile'
[70] Fix | Delete
PATH = '~/Mail'
[71] Fix | Delete
MH_SEQUENCES = '.mh_sequences'
[72] Fix | Delete
FOLDER_PROTECT = 0700
[73] Fix | Delete
[74] Fix | Delete
[75] Fix | Delete
# Imported modules
[76] Fix | Delete
[77] Fix | Delete
import os
[78] Fix | Delete
import sys
[79] Fix | Delete
import re
[80] Fix | Delete
import mimetools
[81] Fix | Delete
import multifile
[82] Fix | Delete
import shutil
[83] Fix | Delete
from bisect import bisect
[84] Fix | Delete
[85] Fix | Delete
__all__ = ["MH","Error","Folder","Message"]
[86] Fix | Delete
[87] Fix | Delete
# Exported constants
[88] Fix | Delete
[89] Fix | Delete
class Error(Exception):
[90] Fix | Delete
pass
[91] Fix | Delete
[92] Fix | Delete
[93] Fix | Delete
class MH:
[94] Fix | Delete
"""Class representing a particular collection of folders.
[95] Fix | Delete
Optional constructor arguments are the pathname for the directory
[96] Fix | Delete
containing the collection, and the MH profile to use.
[97] Fix | Delete
If either is omitted or empty a default is used; the default
[98] Fix | Delete
directory is taken from the MH profile if it is specified there."""
[99] Fix | Delete
[100] Fix | Delete
def __init__(self, path = None, profile = None):
[101] Fix | Delete
"""Constructor."""
[102] Fix | Delete
if profile is None: profile = MH_PROFILE
[103] Fix | Delete
self.profile = os.path.expanduser(profile)
[104] Fix | Delete
if path is None: path = self.getprofile('Path')
[105] Fix | Delete
if not path: path = PATH
[106] Fix | Delete
if not os.path.isabs(path) and path[0] != '~':
[107] Fix | Delete
path = os.path.join('~', path)
[108] Fix | Delete
path = os.path.expanduser(path)
[109] Fix | Delete
if not os.path.isdir(path): raise Error, 'MH() path not found'
[110] Fix | Delete
self.path = path
[111] Fix | Delete
[112] Fix | Delete
def __repr__(self):
[113] Fix | Delete
"""String representation."""
[114] Fix | Delete
return 'MH(%r, %r)' % (self.path, self.profile)
[115] Fix | Delete
[116] Fix | Delete
def error(self, msg, *args):
[117] Fix | Delete
"""Routine to print an error. May be overridden by a derived class."""
[118] Fix | Delete
sys.stderr.write('MH error: %s\n' % (msg % args))
[119] Fix | Delete
[120] Fix | Delete
def getprofile(self, key):
[121] Fix | Delete
"""Return a profile entry, None if not found."""
[122] Fix | Delete
return pickline(self.profile, key)
[123] Fix | Delete
[124] Fix | Delete
def getpath(self):
[125] Fix | Delete
"""Return the path (the name of the collection's directory)."""
[126] Fix | Delete
return self.path
[127] Fix | Delete
[128] Fix | Delete
def getcontext(self):
[129] Fix | Delete
"""Return the name of the current folder."""
[130] Fix | Delete
context = pickline(os.path.join(self.getpath(), 'context'),
[131] Fix | Delete
'Current-Folder')
[132] Fix | Delete
if not context: context = 'inbox'
[133] Fix | Delete
return context
[134] Fix | Delete
[135] Fix | Delete
def setcontext(self, context):
[136] Fix | Delete
"""Set the name of the current folder."""
[137] Fix | Delete
fn = os.path.join(self.getpath(), 'context')
[138] Fix | Delete
f = open(fn, "w")
[139] Fix | Delete
f.write("Current-Folder: %s\n" % context)
[140] Fix | Delete
f.close()
[141] Fix | Delete
[142] Fix | Delete
def listfolders(self):
[143] Fix | Delete
"""Return the names of the top-level folders."""
[144] Fix | Delete
folders = []
[145] Fix | Delete
path = self.getpath()
[146] Fix | Delete
for name in os.listdir(path):
[147] Fix | Delete
fullname = os.path.join(path, name)
[148] Fix | Delete
if os.path.isdir(fullname):
[149] Fix | Delete
folders.append(name)
[150] Fix | Delete
folders.sort()
[151] Fix | Delete
return folders
[152] Fix | Delete
[153] Fix | Delete
def listsubfolders(self, name):
[154] Fix | Delete
"""Return the names of the subfolders in a given folder
[155] Fix | Delete
(prefixed with the given folder name)."""
[156] Fix | Delete
fullname = os.path.join(self.path, name)
[157] Fix | Delete
# Get the link count so we can avoid listing folders
[158] Fix | Delete
# that have no subfolders.
[159] Fix | Delete
nlinks = os.stat(fullname).st_nlink
[160] Fix | Delete
if nlinks == 2:
[161] Fix | Delete
return []
[162] Fix | Delete
subfolders = []
[163] Fix | Delete
subnames = os.listdir(fullname)
[164] Fix | Delete
for subname in subnames:
[165] Fix | Delete
fullsubname = os.path.join(fullname, subname)
[166] Fix | Delete
if os.path.isdir(fullsubname):
[167] Fix | Delete
name_subname = os.path.join(name, subname)
[168] Fix | Delete
subfolders.append(name_subname)
[169] Fix | Delete
# Stop looking for subfolders when
[170] Fix | Delete
# we've seen them all
[171] Fix | Delete
nlinks = nlinks - 1
[172] Fix | Delete
if nlinks == 2:
[173] Fix | Delete
break
[174] Fix | Delete
subfolders.sort()
[175] Fix | Delete
return subfolders
[176] Fix | Delete
[177] Fix | Delete
def listallfolders(self):
[178] Fix | Delete
"""Return the names of all folders and subfolders, recursively."""
[179] Fix | Delete
return self.listallsubfolders('')
[180] Fix | Delete
[181] Fix | Delete
def listallsubfolders(self, name):
[182] Fix | Delete
"""Return the names of subfolders in a given folder, recursively."""
[183] Fix | Delete
fullname = os.path.join(self.path, name)
[184] Fix | Delete
# Get the link count so we can avoid listing folders
[185] Fix | Delete
# that have no subfolders.
[186] Fix | Delete
nlinks = os.stat(fullname).st_nlink
[187] Fix | Delete
if nlinks == 2:
[188] Fix | Delete
return []
[189] Fix | Delete
subfolders = []
[190] Fix | Delete
subnames = os.listdir(fullname)
[191] Fix | Delete
for subname in subnames:
[192] Fix | Delete
if subname[0] == ',' or isnumeric(subname): continue
[193] Fix | Delete
fullsubname = os.path.join(fullname, subname)
[194] Fix | Delete
if os.path.isdir(fullsubname):
[195] Fix | Delete
name_subname = os.path.join(name, subname)
[196] Fix | Delete
subfolders.append(name_subname)
[197] Fix | Delete
if not os.path.islink(fullsubname):
[198] Fix | Delete
subsubfolders = self.listallsubfolders(
[199] Fix | Delete
name_subname)
[200] Fix | Delete
subfolders = subfolders + subsubfolders
[201] Fix | Delete
# Stop looking for subfolders when
[202] Fix | Delete
# we've seen them all
[203] Fix | Delete
nlinks = nlinks - 1
[204] Fix | Delete
if nlinks == 2:
[205] Fix | Delete
break
[206] Fix | Delete
subfolders.sort()
[207] Fix | Delete
return subfolders
[208] Fix | Delete
[209] Fix | Delete
def openfolder(self, name):
[210] Fix | Delete
"""Return a new Folder object for the named folder."""
[211] Fix | Delete
return Folder(self, name)
[212] Fix | Delete
[213] Fix | Delete
def makefolder(self, name):
[214] Fix | Delete
"""Create a new folder (or raise os.error if it cannot be created)."""
[215] Fix | Delete
protect = pickline(self.profile, 'Folder-Protect')
[216] Fix | Delete
if protect and isnumeric(protect):
[217] Fix | Delete
mode = int(protect, 8)
[218] Fix | Delete
else:
[219] Fix | Delete
mode = FOLDER_PROTECT
[220] Fix | Delete
os.mkdir(os.path.join(self.getpath(), name), mode)
[221] Fix | Delete
[222] Fix | Delete
def deletefolder(self, name):
[223] Fix | Delete
"""Delete a folder. This removes files in the folder but not
[224] Fix | Delete
subdirectories. Raise os.error if deleting the folder itself fails."""
[225] Fix | Delete
fullname = os.path.join(self.getpath(), name)
[226] Fix | Delete
for subname in os.listdir(fullname):
[227] Fix | Delete
fullsubname = os.path.join(fullname, subname)
[228] Fix | Delete
try:
[229] Fix | Delete
os.unlink(fullsubname)
[230] Fix | Delete
except os.error:
[231] Fix | Delete
self.error('%s not deleted, continuing...' %
[232] Fix | Delete
fullsubname)
[233] Fix | Delete
os.rmdir(fullname)
[234] Fix | Delete
[235] Fix | Delete
[236] Fix | Delete
numericprog = re.compile('^[1-9][0-9]*$')
[237] Fix | Delete
def isnumeric(str):
[238] Fix | Delete
return numericprog.match(str) is not None
[239] Fix | Delete
[240] Fix | Delete
class Folder:
[241] Fix | Delete
"""Class representing a particular folder."""
[242] Fix | Delete
[243] Fix | Delete
def __init__(self, mh, name):
[244] Fix | Delete
"""Constructor."""
[245] Fix | Delete
self.mh = mh
[246] Fix | Delete
self.name = name
[247] Fix | Delete
if not os.path.isdir(self.getfullname()):
[248] Fix | Delete
raise Error, 'no folder %s' % name
[249] Fix | Delete
[250] Fix | Delete
def __repr__(self):
[251] Fix | Delete
"""String representation."""
[252] Fix | Delete
return 'Folder(%r, %r)' % (self.mh, self.name)
[253] Fix | Delete
[254] Fix | Delete
def error(self, *args):
[255] Fix | Delete
"""Error message handler."""
[256] Fix | Delete
self.mh.error(*args)
[257] Fix | Delete
[258] Fix | Delete
def getfullname(self):
[259] Fix | Delete
"""Return the full pathname of the folder."""
[260] Fix | Delete
return os.path.join(self.mh.path, self.name)
[261] Fix | Delete
[262] Fix | Delete
def getsequencesfilename(self):
[263] Fix | Delete
"""Return the full pathname of the folder's sequences file."""
[264] Fix | Delete
return os.path.join(self.getfullname(), MH_SEQUENCES)
[265] Fix | Delete
[266] Fix | Delete
def getmessagefilename(self, n):
[267] Fix | Delete
"""Return the full pathname of a message in the folder."""
[268] Fix | Delete
return os.path.join(self.getfullname(), str(n))
[269] Fix | Delete
[270] Fix | Delete
def listsubfolders(self):
[271] Fix | Delete
"""Return list of direct subfolders."""
[272] Fix | Delete
return self.mh.listsubfolders(self.name)
[273] Fix | Delete
[274] Fix | Delete
def listallsubfolders(self):
[275] Fix | Delete
"""Return list of all subfolders."""
[276] Fix | Delete
return self.mh.listallsubfolders(self.name)
[277] Fix | Delete
[278] Fix | Delete
def listmessages(self):
[279] Fix | Delete
"""Return the list of messages currently present in the folder.
[280] Fix | Delete
As a side effect, set self.last to the last message (or 0)."""
[281] Fix | Delete
messages = []
[282] Fix | Delete
match = numericprog.match
[283] Fix | Delete
append = messages.append
[284] Fix | Delete
for name in os.listdir(self.getfullname()):
[285] Fix | Delete
if match(name):
[286] Fix | Delete
append(name)
[287] Fix | Delete
messages = map(int, messages)
[288] Fix | Delete
messages.sort()
[289] Fix | Delete
if messages:
[290] Fix | Delete
self.last = messages[-1]
[291] Fix | Delete
else:
[292] Fix | Delete
self.last = 0
[293] Fix | Delete
return messages
[294] Fix | Delete
[295] Fix | Delete
def getsequences(self):
[296] Fix | Delete
"""Return the set of sequences for the folder."""
[297] Fix | Delete
sequences = {}
[298] Fix | Delete
fullname = self.getsequencesfilename()
[299] Fix | Delete
try:
[300] Fix | Delete
f = open(fullname, 'r')
[301] Fix | Delete
except IOError:
[302] Fix | Delete
return sequences
[303] Fix | Delete
while 1:
[304] Fix | Delete
line = f.readline()
[305] Fix | Delete
if not line: break
[306] Fix | Delete
fields = line.split(':')
[307] Fix | Delete
if len(fields) != 2:
[308] Fix | Delete
self.error('bad sequence in %s: %s' %
[309] Fix | Delete
(fullname, line.strip()))
[310] Fix | Delete
key = fields[0].strip()
[311] Fix | Delete
value = IntSet(fields[1].strip(), ' ').tolist()
[312] Fix | Delete
sequences[key] = value
[313] Fix | Delete
return sequences
[314] Fix | Delete
[315] Fix | Delete
def putsequences(self, sequences):
[316] Fix | Delete
"""Write the set of sequences back to the folder."""
[317] Fix | Delete
fullname = self.getsequencesfilename()
[318] Fix | Delete
f = None
[319] Fix | Delete
for key, seq in sequences.iteritems():
[320] Fix | Delete
s = IntSet('', ' ')
[321] Fix | Delete
s.fromlist(seq)
[322] Fix | Delete
if not f: f = open(fullname, 'w')
[323] Fix | Delete
f.write('%s: %s\n' % (key, s.tostring()))
[324] Fix | Delete
if not f:
[325] Fix | Delete
try:
[326] Fix | Delete
os.unlink(fullname)
[327] Fix | Delete
except os.error:
[328] Fix | Delete
pass
[329] Fix | Delete
else:
[330] Fix | Delete
f.close()
[331] Fix | Delete
[332] Fix | Delete
def getcurrent(self):
[333] Fix | Delete
"""Return the current message. Raise Error when there is none."""
[334] Fix | Delete
seqs = self.getsequences()
[335] Fix | Delete
try:
[336] Fix | Delete
return max(seqs['cur'])
[337] Fix | Delete
except (ValueError, KeyError):
[338] Fix | Delete
raise Error, "no cur message"
[339] Fix | Delete
[340] Fix | Delete
def setcurrent(self, n):
[341] Fix | Delete
"""Set the current message."""
[342] Fix | Delete
updateline(self.getsequencesfilename(), 'cur', str(n), 0)
[343] Fix | Delete
[344] Fix | Delete
def parsesequence(self, seq):
[345] Fix | Delete
"""Parse an MH sequence specification into a message list.
[346] Fix | Delete
Attempt to mimic mh-sequence(5) as close as possible.
[347] Fix | Delete
Also attempt to mimic observed behavior regarding which
[348] Fix | Delete
conditions cause which error messages."""
[349] Fix | Delete
# XXX Still not complete (see mh-format(5)).
[350] Fix | Delete
# Missing are:
[351] Fix | Delete
# - 'prev', 'next' as count
[352] Fix | Delete
# - Sequence-Negation option
[353] Fix | Delete
all = self.listmessages()
[354] Fix | Delete
# Observed behavior: test for empty folder is done first
[355] Fix | Delete
if not all:
[356] Fix | Delete
raise Error, "no messages in %s" % self.name
[357] Fix | Delete
# Common case first: all is frequently the default
[358] Fix | Delete
if seq == 'all':
[359] Fix | Delete
return all
[360] Fix | Delete
# Test for X:Y before X-Y because 'seq:-n' matches both
[361] Fix | Delete
i = seq.find(':')
[362] Fix | Delete
if i >= 0:
[363] Fix | Delete
head, dir, tail = seq[:i], '', seq[i+1:]
[364] Fix | Delete
if tail[:1] in '-+':
[365] Fix | Delete
dir, tail = tail[:1], tail[1:]
[366] Fix | Delete
if not isnumeric(tail):
[367] Fix | Delete
raise Error, "bad message list %s" % seq
[368] Fix | Delete
try:
[369] Fix | Delete
count = int(tail)
[370] Fix | Delete
except (ValueError, OverflowError):
[371] Fix | Delete
# Can't use sys.maxint because of i+count below
[372] Fix | Delete
count = len(all)
[373] Fix | Delete
try:
[374] Fix | Delete
anchor = self._parseindex(head, all)
[375] Fix | Delete
except Error, msg:
[376] Fix | Delete
seqs = self.getsequences()
[377] Fix | Delete
if not head in seqs:
[378] Fix | Delete
if not msg:
[379] Fix | Delete
msg = "bad message list %s" % seq
[380] Fix | Delete
raise Error, msg, sys.exc_info()[2]
[381] Fix | Delete
msgs = seqs[head]
[382] Fix | Delete
if not msgs:
[383] Fix | Delete
raise Error, "sequence %s empty" % head
[384] Fix | Delete
if dir == '-':
[385] Fix | Delete
return msgs[-count:]
[386] Fix | Delete
else:
[387] Fix | Delete
return msgs[:count]
[388] Fix | Delete
else:
[389] Fix | Delete
if not dir:
[390] Fix | Delete
if head in ('prev', 'last'):
[391] Fix | Delete
dir = '-'
[392] Fix | Delete
if dir == '-':
[393] Fix | Delete
i = bisect(all, anchor)
[394] Fix | Delete
return all[max(0, i-count):i]
[395] Fix | Delete
else:
[396] Fix | Delete
i = bisect(all, anchor-1)
[397] Fix | Delete
return all[i:i+count]
[398] Fix | Delete
# Test for X-Y next
[399] Fix | Delete
i = seq.find('-')
[400] Fix | Delete
if i >= 0:
[401] Fix | Delete
begin = self._parseindex(seq[:i], all)
[402] Fix | Delete
end = self._parseindex(seq[i+1:], all)
[403] Fix | Delete
i = bisect(all, begin-1)
[404] Fix | Delete
j = bisect(all, end)
[405] Fix | Delete
r = all[i:j]
[406] Fix | Delete
if not r:
[407] Fix | Delete
raise Error, "bad message list %s" % seq
[408] Fix | Delete
return r
[409] Fix | Delete
# Neither X:Y nor X-Y; must be a number or a (pseudo-)sequence
[410] Fix | Delete
try:
[411] Fix | Delete
n = self._parseindex(seq, all)
[412] Fix | Delete
except Error, msg:
[413] Fix | Delete
seqs = self.getsequences()
[414] Fix | Delete
if not seq in seqs:
[415] Fix | Delete
if not msg:
[416] Fix | Delete
msg = "bad message list %s" % seq
[417] Fix | Delete
raise Error, msg
[418] Fix | Delete
return seqs[seq]
[419] Fix | Delete
else:
[420] Fix | Delete
if n not in all:
[421] Fix | Delete
if isnumeric(seq):
[422] Fix | Delete
raise Error, "message %d doesn't exist" % n
[423] Fix | Delete
else:
[424] Fix | Delete
raise Error, "no %s message" % seq
[425] Fix | Delete
else:
[426] Fix | Delete
return [n]
[427] Fix | Delete
[428] Fix | Delete
def _parseindex(self, seq, all):
[429] Fix | Delete
"""Internal: parse a message number (or cur, first, etc.)."""
[430] Fix | Delete
if isnumeric(seq):
[431] Fix | Delete
try:
[432] Fix | Delete
return int(seq)
[433] Fix | Delete
except (OverflowError, ValueError):
[434] Fix | Delete
return sys.maxint
[435] Fix | Delete
if seq in ('cur', '.'):
[436] Fix | Delete
return self.getcurrent()
[437] Fix | Delete
if seq == 'first':
[438] Fix | Delete
return all[0]
[439] Fix | Delete
if seq == 'last':
[440] Fix | Delete
return all[-1]
[441] Fix | Delete
if seq == 'next':
[442] Fix | Delete
n = self.getcurrent()
[443] Fix | Delete
i = bisect(all, n)
[444] Fix | Delete
try:
[445] Fix | Delete
return all[i]
[446] Fix | Delete
except IndexError:
[447] Fix | Delete
raise Error, "no next message"
[448] Fix | Delete
if seq == 'prev':
[449] Fix | Delete
n = self.getcurrent()
[450] Fix | Delete
i = bisect(all, n-1)
[451] Fix | Delete
if i == 0:
[452] Fix | Delete
raise Error, "no prev message"
[453] Fix | Delete
try:
[454] Fix | Delete
return all[i-1]
[455] Fix | Delete
except IndexError:
[456] Fix | Delete
raise Error, "no prev message"
[457] Fix | Delete
raise Error, None
[458] Fix | Delete
[459] Fix | Delete
def openmessage(self, n):
[460] Fix | Delete
"""Open a message -- returns a Message object."""
[461] Fix | Delete
return Message(self, n)
[462] Fix | Delete
[463] Fix | Delete
def removemessages(self, list):
[464] Fix | Delete
"""Remove one or more messages -- may raise os.error."""
[465] Fix | Delete
errors = []
[466] Fix | Delete
deleted = []
[467] Fix | Delete
for n in list:
[468] Fix | Delete
path = self.getmessagefilename(n)
[469] Fix | Delete
commapath = self.getmessagefilename(',' + str(n))
[470] Fix | Delete
try:
[471] Fix | Delete
os.unlink(commapath)
[472] Fix | Delete
except os.error:
[473] Fix | Delete
pass
[474] Fix | Delete
try:
[475] Fix | Delete
os.rename(path, commapath)
[476] Fix | Delete
except os.error, msg:
[477] Fix | Delete
errors.append(msg)
[478] Fix | Delete
else:
[479] Fix | Delete
deleted.append(n)
[480] Fix | Delete
if deleted:
[481] Fix | Delete
self.removefromallsequences(deleted)
[482] Fix | Delete
if errors:
[483] Fix | Delete
if len(errors) == 1:
[484] Fix | Delete
raise os.error, errors[0]
[485] Fix | Delete
else:
[486] Fix | Delete
raise os.error, ('multiple errors:', errors)
[487] Fix | Delete
[488] Fix | Delete
def refilemessages(self, list, tofolder, keepsequences=0):
[489] Fix | Delete
"""Refile one or more messages -- may raise os.error.
[490] Fix | Delete
'tofolder' is an open folder object."""
[491] Fix | Delete
errors = []
[492] Fix | Delete
refiled = {}
[493] Fix | Delete
for n in list:
[494] Fix | Delete
ton = tofolder.getlast() + 1
[495] Fix | Delete
path = self.getmessagefilename(n)
[496] Fix | Delete
topath = tofolder.getmessagefilename(ton)
[497] Fix | Delete
try:
[498] Fix | Delete
os.rename(path, topath)
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function