interfaces.py 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070
  1. # Copyright (c) Twisted Matrix Laboratories.
  2. # See LICENSE for details.
  3. """
  4. Interfaces for L{twisted.mail}.
  5. @since: 16.5
  6. """
  7. from __future__ import absolute_import, division
  8. from zope.interface import Interface
  9. class IClientAuthentication(Interface):
  10. def getName():
  11. """
  12. Return an identifier associated with this authentication scheme.
  13. @rtype: L{bytes}
  14. """
  15. def challengeResponse(secret, challenge):
  16. """
  17. Generate a challenge response string.
  18. """
  19. class IServerFactoryPOP3(Interface):
  20. """
  21. An interface for querying capabilities of a POP3 server.
  22. Any cap_* method may raise L{NotImplementedError} if the particular
  23. capability is not supported. If L{cap_EXPIRE()} does not raise
  24. L{NotImplementedError}, L{perUserExpiration()} must be implemented,
  25. otherwise they are optional. If L{cap_LOGIN_DELAY()} is implemented,
  26. L{perUserLoginDelay()} must be implemented, otherwise they are optional.
  27. @type challengers: L{dict} of L{bytes} -> L{IUsernameHashedPassword
  28. <cred.credentials.IUsernameHashedPassword>}
  29. @ivar challengers: A mapping of challenger names to
  30. L{IUsernameHashedPassword <cred.credentials.IUsernameHashedPassword>}
  31. provider.
  32. """
  33. def cap_IMPLEMENTATION():
  34. """
  35. Return a string describing the POP3 server implementation.
  36. @rtype: L{bytes}
  37. @return: Server implementation information.
  38. """
  39. def cap_EXPIRE():
  40. """
  41. Return the minimum number of days messages are retained.
  42. @rtype: L{int} or L{None}
  43. @return: The minimum number of days messages are retained or none, if
  44. the server never deletes messages.
  45. """
  46. def perUserExpiration():
  47. """
  48. Indicate whether the message expiration policy differs per user.
  49. @rtype: L{bool}
  50. @return: C{True} when the message expiration policy differs per user,
  51. C{False} otherwise.
  52. """
  53. def cap_LOGIN_DELAY():
  54. """
  55. Return the minimum number of seconds between client logins.
  56. @rtype: L{int}
  57. @return: The minimum number of seconds between client logins.
  58. """
  59. def perUserLoginDelay():
  60. """
  61. Indicate whether the login delay period differs per user.
  62. @rtype: L{bool}
  63. @return: C{True} when the login delay differs per user, C{False}
  64. otherwise.
  65. """
  66. class IMailboxPOP3(Interface):
  67. """
  68. An interface for mailbox access.
  69. Message indices are 0-based.
  70. @type loginDelay: L{int}
  71. @ivar loginDelay: The number of seconds between allowed logins for the
  72. user associated with this mailbox.
  73. @type messageExpiration: L{int}
  74. @ivar messageExpiration: The number of days messages in this mailbox will
  75. remain on the server before being deleted.
  76. """
  77. def listMessages(index=None):
  78. """
  79. Retrieve the size of a message, or, if none is specified, the size of
  80. each message in the mailbox.
  81. @type index: L{int} or L{None}
  82. @param index: The 0-based index of the message.
  83. @rtype: L{int}, sequence of L{int}, or L{Deferred <defer.Deferred>}
  84. @return: The number of octets in the specified message, or, if an
  85. index is not specified, a sequence of the number of octets for
  86. all messages in the mailbox or a deferred which fires with
  87. one of those. Any value which corresponds to a deleted message
  88. is set to 0.
  89. @raise ValueError or IndexError: When the index does not correspond to
  90. a message in the mailbox. The use of ValueError is preferred.
  91. """
  92. def getMessage(index):
  93. """
  94. Retrieve a file containing the contents of a message.
  95. @type index: L{int}
  96. @param index: The 0-based index of a message.
  97. @rtype: file-like object
  98. @return: A file containing the message.
  99. @raise ValueError or IndexError: When the index does not correspond to
  100. a message in the mailbox. The use of ValueError is preferred.
  101. """
  102. def getUidl(index):
  103. """
  104. Get a unique identifier for a message.
  105. @type index: L{int}
  106. @param index: The 0-based index of a message.
  107. @rtype: L{bytes}
  108. @return: A string of printable characters uniquely identifying the
  109. message for all time.
  110. @raise ValueError or IndexError: When the index does not correspond to
  111. a message in the mailbox. The use of ValueError is preferred.
  112. """
  113. def deleteMessage(index):
  114. """
  115. Mark a message for deletion.
  116. This must not change the number of messages in this mailbox. Further
  117. requests for the size of the deleted message should return 0. Further
  118. requests for the message itself may raise an exception.
  119. @type index: L{int}
  120. @param index: The 0-based index of a message.
  121. @raise ValueError or IndexError: When the index does not correspond to
  122. a message in the mailbox. The use of ValueError is preferred.
  123. """
  124. def undeleteMessages():
  125. """
  126. Undelete all messages marked for deletion.
  127. Any message which can be undeleted should be returned to its original
  128. position in the message sequence and retain its original UID.
  129. """
  130. def sync():
  131. """
  132. Discard the contents of any message marked for deletion.
  133. """
  134. class IDomain(Interface):
  135. """
  136. An interface for email domains.
  137. """
  138. def exists(user):
  139. """
  140. Check whether a user exists in this domain.
  141. @type user: L{User}
  142. @param user: A user.
  143. @rtype: no-argument callable which returns L{IMessageSMTP} provider
  144. @return: A function which takes no arguments and returns a message
  145. receiver for the user.
  146. @raise SMTPBadRcpt: When the given user does not exist in this domain.
  147. """
  148. def addUser(user, password):
  149. """
  150. Add a user to this domain.
  151. @type user: L{bytes}
  152. @param user: A username.
  153. @type password: L{bytes}
  154. @param password: A password.
  155. """
  156. def getCredentialsCheckers():
  157. """
  158. Return credentials checkers for this domain.
  159. @rtype: L{list} of L{ICredentialsChecker
  160. <twisted.cred.checkers.ICredentialsChecker>} provider
  161. @return: Credentials checkers for this domain.
  162. """
  163. class IAlias(Interface):
  164. """
  165. An interface for aliases.
  166. """
  167. def createMessageReceiver():
  168. """
  169. Create a message receiver.
  170. @rtype: L{IMessageSMTP} provider
  171. @return: A message receiver.
  172. """
  173. class IAliasableDomain(IDomain):
  174. """
  175. An interface for email domains which can be aliased to other domains.
  176. """
  177. def setAliasGroup(aliases):
  178. """
  179. Set the group of defined aliases for this domain.
  180. @type aliases: L{dict} of L{bytes} -> L{IAlias} provider
  181. @param aliases: A mapping of domain name to alias.
  182. """
  183. def exists(user, memo=None):
  184. """
  185. Check whether a user exists in this domain or an alias of it.
  186. @type user: L{User}
  187. @param user: A user.
  188. @type memo: L{None} or L{dict} of
  189. L{AliasBase <twisted.mail.alias.AliasBase>}
  190. @param memo: A record of the addresses already considered while
  191. resolving aliases. The default value should be used by all external
  192. code.
  193. @rtype: no-argument callable which returns L{IMessageSMTP} provider
  194. @return: A function which takes no arguments and returns a message
  195. receiver for the user.
  196. @raise SMTPBadRcpt: When the given user does not exist in this domain
  197. or an alias of it.
  198. """
  199. class IMessageDelivery(Interface):
  200. def receivedHeader(helo, origin, recipients):
  201. """
  202. Generate the Received header for a message.
  203. @type helo: 2-L{tuple} of L{bytes} and L{bytes}.
  204. @param helo: The argument to the HELO command and the client's IP
  205. address.
  206. @type origin: L{Address}
  207. @param origin: The address the message is from
  208. @type recipients: L{list} of L{User}
  209. @param recipients: A list of the addresses for which this message
  210. is bound.
  211. @rtype: L{bytes}
  212. @return: The full C{"Received"} header string.
  213. """
  214. def validateTo(user):
  215. """
  216. Validate the address for which the message is destined.
  217. @type user: L{User}
  218. @param user: The address to validate.
  219. @rtype: no-argument callable
  220. @return: A L{Deferred} which becomes, or a callable which takes no
  221. arguments and returns an object implementing L{IMessageSMTP}. This
  222. will be called and the returned object used to deliver the message
  223. when it arrives.
  224. @raise SMTPBadRcpt: Raised if messages to the address are not to be
  225. accepted.
  226. """
  227. def validateFrom(helo, origin):
  228. """
  229. Validate the address from which the message originates.
  230. @type helo: 2-L{tuple} of L{bytes} and L{bytes}.
  231. @param helo: The argument to the HELO command and the client's IP
  232. address.
  233. @type origin: L{Address}
  234. @param origin: The address the message is from
  235. @rtype: L{Deferred} or L{Address}
  236. @return: C{origin} or a L{Deferred} whose callback will be
  237. passed C{origin}.
  238. @raise SMTPBadSender: Raised of messages from this address are
  239. not to be accepted.
  240. """
  241. class IMessageDeliveryFactory(Interface):
  242. """
  243. An alternate interface to implement for handling message delivery.
  244. It is useful to implement this interface instead of L{IMessageDelivery}
  245. directly because it allows the implementor to distinguish between different
  246. messages delivery over the same connection. This can be used to optimize
  247. delivery of a single message to multiple recipients, something which cannot
  248. be done by L{IMessageDelivery} implementors due to their lack of
  249. information.
  250. """
  251. def getMessageDelivery():
  252. """
  253. Return an L{IMessageDelivery} object.
  254. This will be called once per message.
  255. """
  256. class IMessageSMTP(Interface):
  257. """
  258. Interface definition for messages that can be sent via SMTP.
  259. """
  260. def lineReceived(line):
  261. """
  262. Handle another line.
  263. """
  264. def eomReceived():
  265. """
  266. Handle end of message.
  267. return a deferred. The deferred should be called with either:
  268. callback(string) or errback(error)
  269. @rtype: L{Deferred}
  270. """
  271. def connectionLost():
  272. """
  273. Handle message truncated.
  274. semantics should be to discard the message
  275. """
  276. class IMessageIMAPPart(Interface):
  277. def getHeaders(negate, *names):
  278. """
  279. Retrieve a group of message headers.
  280. @type names: L{tuple} of L{bytes}
  281. @param names: The names of the headers to retrieve or omit.
  282. @type negate: L{bool}
  283. @param negate: If True, indicates that the headers listed in C{names}
  284. should be omitted from the return value, rather than included.
  285. @rtype: L{dict}
  286. @return: A mapping of header field names to header field values
  287. """
  288. def getBodyFile():
  289. """
  290. Retrieve a file object containing only the body of this message.
  291. """
  292. def getSize():
  293. """
  294. Retrieve the total size, in octets, of this message.
  295. @rtype: L{int}
  296. """
  297. def isMultipart():
  298. """
  299. Indicate whether this message has subparts.
  300. @rtype: L{bool}
  301. """
  302. def getSubPart(part):
  303. """
  304. Retrieve a MIME sub-message
  305. @type part: L{int}
  306. @param part: The number of the part to retrieve, indexed from 0.
  307. @raise IndexError: Raised if the specified part does not exist.
  308. @raise TypeError: Raised if this message is not multipart.
  309. @rtype: Any object implementing L{IMessageIMAPPart}.
  310. @return: The specified sub-part.
  311. """
  312. class IMessageIMAP(IMessageIMAPPart):
  313. def getUID():
  314. """
  315. Retrieve the unique identifier associated with this message.
  316. """
  317. def getFlags():
  318. """
  319. Retrieve the flags associated with this message.
  320. @rtype: C{iterable}
  321. @return: The flags, represented as strings.
  322. """
  323. def getInternalDate():
  324. """
  325. Retrieve the date internally associated with this message.
  326. @rtype: L{bytes}
  327. @return: An RFC822-formatted date string.
  328. """
  329. class IMessageIMAPFile(Interface):
  330. """
  331. Optional message interface for representing messages as files.
  332. If provided by message objects, this interface will be used instead the
  333. more complex MIME-based interface.
  334. """
  335. def open():
  336. """
  337. Return a file-like object opened for reading.
  338. Reading from the returned file will return all the bytes of which this
  339. message consists.
  340. """
  341. class ISearchableIMAPMailbox(Interface):
  342. def search(query, uid):
  343. """
  344. Search for messages that meet the given query criteria.
  345. If this interface is not implemented by the mailbox,
  346. L{IMailboxIMAP.fetch} and various methods of L{IMessageIMAP} will be
  347. used instead.
  348. Implementations which wish to offer better performance than the default
  349. implementation should implement this interface.
  350. @type query: L{list}
  351. @param query: The search criteria
  352. @type uid: L{bool}
  353. @param uid: If true, the IDs specified in the query are UIDs; otherwise
  354. they are message sequence IDs.
  355. @rtype: L{list} or L{Deferred}
  356. @return: A list of message sequence numbers or message UIDs which match
  357. the search criteria or a L{Deferred} whose callback will be invoked
  358. with such a list.
  359. @raise IllegalQueryError: Raised when query is not valid.
  360. """
  361. class IMailboxIMAPListener(Interface):
  362. """
  363. Interface for objects interested in mailbox events
  364. """
  365. def modeChanged(writeable):
  366. """
  367. Indicates that the write status of a mailbox has changed.
  368. @type writeable: L{bool}
  369. @param writeable: A true value if write is now allowed, false
  370. otherwise.
  371. """
  372. def flagsChanged(newFlags):
  373. """
  374. Indicates that the flags of one or more messages have changed.
  375. @type newFlags: L{dict}
  376. @param newFlags: A mapping of message identifiers to tuples of flags
  377. now set on that message.
  378. """
  379. def newMessages(exists, recent):
  380. """
  381. Indicates that the number of messages in a mailbox has changed.
  382. @type exists: L{int} or L{None}
  383. @param exists: The total number of messages now in this mailbox. If the
  384. total number of messages has not changed, this should be L{None}.
  385. @type recent: L{int}
  386. @param recent: The number of messages now flagged C{\\Recent}. If the
  387. number of recent messages has not changed, this should be L{None}.
  388. """
  389. class IMessageIMAPCopier(Interface):
  390. def copy(messageObject):
  391. """
  392. Copy the given message object into this mailbox.
  393. The message object will be one which was previously returned by
  394. L{IMailboxIMAP.fetch}.
  395. Implementations which wish to offer better performance than the default
  396. implementation should implement this interface.
  397. If this interface is not implemented by the mailbox,
  398. L{IMailboxIMAP.addMessage} will be used instead.
  399. @rtype: L{Deferred} or L{int}
  400. @return: Either the UID of the message or a Deferred which fires with
  401. the UID when the copy finishes.
  402. """
  403. class IMailboxIMAPInfo(Interface):
  404. """
  405. Interface specifying only the methods required for C{listMailboxes}.
  406. Implementations can return objects implementing only these methods for
  407. return to C{listMailboxes} if it can allow them to operate more
  408. efficiently.
  409. """
  410. def getFlags():
  411. """
  412. Return the flags defined in this mailbox
  413. Flags with the \\ prefix are reserved for use as system flags.
  414. @rtype: L{list} of L{bytes}
  415. @return: A list of the flags that can be set on messages in this
  416. mailbox.
  417. """
  418. def getHierarchicalDelimiter():
  419. """
  420. Get the character which delimits namespaces for in this mailbox.
  421. @rtype: L{bytes}
  422. """
  423. class IMailboxIMAP(IMailboxIMAPInfo):
  424. def getUIDValidity():
  425. """
  426. Return the unique validity identifier for this mailbox.
  427. @rtype: L{int}
  428. """
  429. def getUIDNext():
  430. """
  431. Return the likely UID for the next message added to this mailbox.
  432. @rtype: L{int}
  433. """
  434. def getUID(message):
  435. """
  436. Return the UID of a message in the mailbox
  437. @type message: L{int}
  438. @param message: The message sequence number
  439. @rtype: L{int}
  440. @return: The UID of the message.
  441. """
  442. def getMessageCount():
  443. """
  444. Return the number of messages in this mailbox.
  445. @rtype: L{int}
  446. """
  447. def getRecentCount():
  448. """
  449. Return the number of messages with the 'Recent' flag.
  450. @rtype: L{int}
  451. """
  452. def getUnseenCount():
  453. """
  454. Return the number of messages with the 'Unseen' flag.
  455. @rtype: L{int}
  456. """
  457. def isWriteable():
  458. """
  459. Get the read/write status of the mailbox.
  460. @rtype: L{int}
  461. @return: A true value if write permission is allowed, a false value
  462. otherwise.
  463. """
  464. def destroy():
  465. """
  466. Called before this mailbox is deleted, permanently.
  467. If necessary, all resources held by this mailbox should be cleaned up
  468. here. This function _must_ set the \\Noselect flag on this mailbox.
  469. """
  470. def requestStatus(names):
  471. """
  472. Return status information about this mailbox.
  473. Mailboxes which do not intend to do any special processing to generate
  474. the return value, C{statusRequestHelper} can be used to build the
  475. dictionary by calling the other interface methods which return the data
  476. for each name.
  477. @type names: Any iterable
  478. @param names: The status names to return information regarding. The
  479. possible values for each name are: MESSAGES, RECENT, UIDNEXT,
  480. UIDVALIDITY, UNSEEN.
  481. @rtype: L{dict} or L{Deferred}
  482. @return: A dictionary containing status information about the requested
  483. names is returned. If the process of looking this information up
  484. would be costly, a deferred whose callback will eventually be
  485. passed this dictionary is returned instead.
  486. """
  487. def addListener(listener):
  488. """
  489. Add a mailbox change listener
  490. @type listener: Any object which implements C{IMailboxIMAPListener}
  491. @param listener: An object to add to the set of those which will be
  492. notified when the contents of this mailbox change.
  493. """
  494. def removeListener(listener):
  495. """
  496. Remove a mailbox change listener
  497. @type listener: Any object previously added to and not removed from
  498. this mailbox as a listener.
  499. @param listener: The object to remove from the set of listeners.
  500. @raise ValueError: Raised when the given object is not a listener for
  501. this mailbox.
  502. """
  503. def addMessage(message, flags=(), date=None):
  504. """
  505. Add the given message to this mailbox.
  506. @type message: A file-like object
  507. @param message: The RFC822 formatted message
  508. @type flags: Any iterable of L{bytes}
  509. @param flags: The flags to associate with this message
  510. @type date: L{bytes}
  511. @param date: If specified, the date to associate with this message.
  512. @rtype: L{Deferred}
  513. @return: A deferred whose callback is invoked with the message id if
  514. the message is added successfully and whose errback is invoked
  515. otherwise.
  516. @raise ReadOnlyMailbox: Raised if this Mailbox is not open for
  517. read-write.
  518. """
  519. def expunge():
  520. """
  521. Remove all messages flagged \\Deleted.
  522. @rtype: L{list} or L{Deferred}
  523. @return: The list of message sequence numbers which were deleted, or a
  524. L{Deferred} whose callback will be invoked with such a list.
  525. @raise ReadOnlyMailbox: Raised if this Mailbox is not open for
  526. read-write.
  527. """
  528. def fetch(messages, uid):
  529. """
  530. Retrieve one or more messages.
  531. @type messages: C{MessageSet}
  532. @param messages: The identifiers of messages to retrieve information
  533. about
  534. @type uid: L{bool}
  535. @param uid: If true, the IDs specified in the query are UIDs; otherwise
  536. they are message sequence IDs.
  537. @rtype: Any iterable of two-tuples of message sequence numbers and
  538. implementors of C{IMessageIMAP}.
  539. """
  540. def store(messages, flags, mode, uid):
  541. """
  542. Set the flags of one or more messages.
  543. @type messages: A MessageSet object with the list of messages requested
  544. @param messages: The identifiers of the messages to set the flags of.
  545. @type flags: sequence of L{bytes}
  546. @param flags: The flags to set, unset, or add.
  547. @type mode: -1, 0, or 1
  548. @param mode: If mode is -1, these flags should be removed from the
  549. specified messages. If mode is 1, these flags should be added to
  550. the specified messages. If mode is 0, all existing flags should be
  551. cleared and these flags should be added.
  552. @type uid: L{bool}
  553. @param uid: If true, the IDs specified in the query are UIDs; otherwise
  554. they are message sequence IDs.
  555. @rtype: L{dict} or L{Deferred}
  556. @return: A L{dict} mapping message sequence numbers to sequences of
  557. L{bytes} representing the flags set on the message after this
  558. operation has been performed, or a L{Deferred} whose callback will
  559. be invoked with such a L{dict}.
  560. @raise ReadOnlyMailbox: Raised if this mailbox is not open for
  561. read-write.
  562. """
  563. class ICloseableMailboxIMAP(Interface):
  564. """
  565. A supplementary interface for mailboxes which require cleanup on close.
  566. Implementing this interface is optional. If it is implemented, the protocol
  567. code will call the close method defined whenever a mailbox is closed.
  568. """
  569. def close():
  570. """
  571. Close this mailbox.
  572. @return: A L{Deferred} which fires when this mailbox has been closed,
  573. or None if the mailbox can be closed immediately.
  574. """
  575. class IAccountIMAP(Interface):
  576. """
  577. Interface for Account classes
  578. Implementors of this interface should consider implementing
  579. C{INamespacePresenter}.
  580. """
  581. def addMailbox(name, mbox=None):
  582. """
  583. Add a new mailbox to this account
  584. @type name: L{bytes}
  585. @param name: The name associated with this mailbox. It may not contain
  586. multiple hierarchical parts.
  587. @type mbox: An object implementing C{IMailboxIMAP}
  588. @param mbox: The mailbox to associate with this name. If L{None}, a
  589. suitable default is created and used.
  590. @rtype: L{Deferred} or L{bool}
  591. @return: A true value if the creation succeeds, or a deferred whose
  592. callback will be invoked when the creation succeeds.
  593. @raise MailboxException: Raised if this mailbox cannot be added for
  594. some reason. This may also be raised asynchronously, if a
  595. L{Deferred} is returned.
  596. """
  597. def create(pathspec):
  598. """
  599. Create a new mailbox from the given hierarchical name.
  600. @type pathspec: L{bytes}
  601. @param pathspec: The full hierarchical name of a new mailbox to create.
  602. If any of the inferior hierarchical names to this one do not exist,
  603. they are created as well.
  604. @rtype: L{Deferred} or L{bool}
  605. @return: A true value if the creation succeeds, or a deferred whose
  606. callback will be invoked when the creation succeeds.
  607. @raise MailboxException: Raised if this mailbox cannot be added. This
  608. may also be raised asynchronously, if a L{Deferred} is returned.
  609. """
  610. def select(name, rw=True):
  611. """
  612. Acquire a mailbox, given its name.
  613. @type name: L{bytes}
  614. @param name: The mailbox to acquire
  615. @type rw: L{bool}
  616. @param rw: If a true value, request a read-write version of this
  617. mailbox. If a false value, request a read-only version.
  618. @rtype: Any object implementing C{IMailboxIMAP} or L{Deferred}
  619. @return: The mailbox object, or a L{Deferred} whose callback will be
  620. invoked with the mailbox object. None may be returned if the
  621. specified mailbox may not be selected for any reason.
  622. """
  623. def delete(name):
  624. """
  625. Delete the mailbox with the specified name.
  626. @type name: L{bytes}
  627. @param name: The mailbox to delete.
  628. @rtype: L{Deferred} or L{bool}
  629. @return: A true value if the mailbox is successfully deleted, or a
  630. L{Deferred} whose callback will be invoked when the deletion
  631. completes.
  632. @raise MailboxException: Raised if this mailbox cannot be deleted. This
  633. may also be raised asynchronously, if a L{Deferred} is returned.
  634. """
  635. def rename(oldname, newname):
  636. """
  637. Rename a mailbox
  638. @type oldname: L{bytes}
  639. @param oldname: The current name of the mailbox to rename.
  640. @type newname: L{bytes}
  641. @param newname: The new name to associate with the mailbox.
  642. @rtype: L{Deferred} or L{bool}
  643. @return: A true value if the mailbox is successfully renamed, or a
  644. L{Deferred} whose callback will be invoked when the rename
  645. operation is completed.
  646. @raise MailboxException: Raised if this mailbox cannot be renamed. This
  647. may also be raised asynchronously, if a L{Deferred} is returned.
  648. """
  649. def isSubscribed(name):
  650. """
  651. Check the subscription status of a mailbox
  652. @type name: L{bytes}
  653. @param name: The name of the mailbox to check
  654. @rtype: L{Deferred} or L{bool}
  655. @return: A true value if the given mailbox is currently subscribed to,
  656. a false value otherwise. A L{Deferred} may also be returned whose
  657. callback will be invoked with one of these values.
  658. """
  659. def subscribe(name):
  660. """
  661. Subscribe to a mailbox
  662. @type name: L{bytes}
  663. @param name: The name of the mailbox to subscribe to
  664. @rtype: L{Deferred} or L{bool}
  665. @return: A true value if the mailbox is subscribed to successfully, or
  666. a Deferred whose callback will be invoked with this value when the
  667. subscription is successful.
  668. @raise MailboxException: Raised if this mailbox cannot be subscribed
  669. to. This may also be raised asynchronously, if a L{Deferred} is
  670. returned.
  671. """
  672. def unsubscribe(name):
  673. """
  674. Unsubscribe from a mailbox
  675. @type name: L{bytes}
  676. @param name: The name of the mailbox to unsubscribe from
  677. @rtype: L{Deferred} or L{bool}
  678. @return: A true value if the mailbox is unsubscribed from successfully,
  679. or a Deferred whose callback will be invoked with this value when
  680. the unsubscription is successful.
  681. @raise MailboxException: Raised if this mailbox cannot be unsubscribed
  682. from. This may also be raised asynchronously, if a L{Deferred} is
  683. returned.
  684. """
  685. def listMailboxes(ref, wildcard):
  686. """
  687. List all the mailboxes that meet a certain criteria
  688. @type ref: L{bytes}
  689. @param ref: The context in which to apply the wildcard
  690. @type wildcard: L{bytes}
  691. @param wildcard: An expression against which to match mailbox names.
  692. '*' matches any number of characters in a mailbox name, and '%'
  693. matches similarly, but will not match across hierarchical
  694. boundaries.
  695. @rtype: L{list} of L{tuple}
  696. @return: A list of C{(mailboxName, mailboxObject)} which meet the given
  697. criteria. C{mailboxObject} should implement either
  698. C{IMailboxIMAPInfo} or C{IMailboxIMAP}. A Deferred may also be
  699. returned.
  700. """
  701. class INamespacePresenter(Interface):
  702. def getPersonalNamespaces():
  703. """
  704. Report the available personal namespaces.
  705. Typically there should be only one personal namespace. A common name
  706. for it is C{\"\"}, and its hierarchical delimiter is usually C{\"/\"}.
  707. @rtype: iterable of two-tuples of strings
  708. @return: The personal namespaces and their hierarchical delimiters. If
  709. no namespaces of this type exist, None should be returned.
  710. """
  711. def getSharedNamespaces():
  712. """
  713. Report the available shared namespaces.
  714. Shared namespaces do not belong to any individual user but are usually
  715. to one or more of them. Examples of shared namespaces might be
  716. C{\"#news\"} for a usenet gateway.
  717. @rtype: iterable of two-tuples of strings
  718. @return: The shared namespaces and their hierarchical delimiters. If no
  719. namespaces of this type exist, None should be returned.
  720. """
  721. def getUserNamespaces():
  722. """
  723. Report the available user namespaces.
  724. These are namespaces that contain folders belonging to other users
  725. access to which this account has been granted.
  726. @rtype: iterable of two-tuples of strings
  727. @return: The user namespaces and their hierarchical delimiters. If no
  728. namespaces of this type exist, None should be returned.
  729. """
  730. __all__ = [
  731. # IMAP
  732. 'IAccountIMAP', 'ICloseableMailboxIMAP', 'IMailboxIMAP',
  733. 'IMailboxIMAPInfo', 'IMailboxIMAPListener', 'IMessageIMAP',
  734. 'IMessageIMAPCopier', 'IMessageIMAPFile', 'IMessageIMAPPart',
  735. 'ISearchableIMAPMailbox', 'INamespacePresenter',
  736. # SMTP
  737. 'IMessageDelivery', 'IMessageDeliveryFactory', 'IMessageSMTP',
  738. # Domains and aliases
  739. 'IDomain', 'IAlias', 'IAliasableDomain',
  740. # POP3
  741. 'IMailboxPOP3', 'IServerFactoryPOP3',
  742. # Authentication
  743. 'IClientAuthentication',
  744. ]