def test_default_value(self): message_class = MessageClass() assert message_class.value == MessageClassOption.ham
def test_bytes(self): message_class = MessageClass(MessageClassOption.ham) assert bytes(message_class) == b'Message-class: ham\r\n'
def test_repr(self): message_class = MessageClass(MessageClassOption.ham) assert repr( message_class) == 'MessageClass(value=MessageClassOption.ham)'
def test_instantiates(self): message_class = MessageClass() assert 'message_class' in locals()
def test_field_name(self): message_class = MessageClass() assert message_class.field_name() == 'Message-class'
def test_user_value_spam(self): message_class = MessageClass(MessageClassOption.spam) assert message_class.value == MessageClassOption.spam
def test_user_value_ham(): message_class = MessageClass(MessageClassOption.ham) assert message_class.value == MessageClassOption.ham
async def tell(self, message_class, message, remove_action=None, set_action=None, ): '''Instruct the SPAMD service to to mark the message Parameters ---------- message_class : :class:`aiospamc.options.MessageClassOption` An enumeration to classify the message as 'spam' or 'ham.' message : :obj:`str` A string containing the contents of the message to be scanned. SPAMD will perform a scan on the included message. SPAMD expects an RFC 822 or RFC 2822 formatted email. remove_action : :class:`aiospamc.options.ActionOption` Remove message class for message in database. set_action : :class:`aiospamc.options.ActionOption` Set message class for message in database. Returns ------- :class:`aiospamc.responses.Response` Will contain a 'Spam' header if the message is marked as spam as well as the score and threshold. The body will contain a report composed by the SPAMD service only if message is marked as being spam. Raises ------ :class:`aiospamc.exceptions.BadResponse` If the response from SPAMD is ill-formed this exception will be raised. :class:`aiospamc.exceptions.AIOSpamcConnectionFailed` Raised if an error occurred when trying to connect. :class:`aiospamc.exceptions.UsageException` Error in command line usage. :class:`aiospamc.exceptions.DataErrorException` Error with data format. :class:`aiospamc.exceptions.NoInputException` Cannot open input. :class:`aiospamc.exceptions.NoUserException` Addressee unknown. :class:`aiospamc.exceptions.NoHostException` Hostname unknown. :class:`aiospamc.exceptions.UnavailableException` Service unavailable. :class:`aiospamc.exceptions.InternalSoftwareException` Internal software error. :class:`aiospamc.exceptions.OSErrorException` System error. :class:`aiospamc.exceptions.OSFileException` Operating system file missing. :class:`aiospamc.exceptions.CantCreateException` Cannot create output file. :class:`aiospamc.exceptions.IOErrorException` Input/output error. :class:`aiospamc.exceptions.TemporaryFailureException` Temporary failure, may reattempt. :class:`aiospamc.exceptions.ProtocolException` Error in the protocol. :class:`aiospamc.exceptions.NoPermissionException` Permission denied. :class:`aiospamc.exceptions.ConfigException` Error in configuration. :class:`aiospamc.exceptions.TimeoutException` Timeout during connection. ''' request = Request(verb='TELL', headers=(MessageClass(message_class),), body=message) if remove_action: request.add_header(Set(remove_action)) if set_action: request.add_header(Remove(set_action)) self.logger.debug('Composed %s request (%s)', request.verb, id(request)) response = await self.send(request) return response