interfaces.py 31 KB

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