 		props.type = @TYPE_MAIL
 		props.processed = false
 
+		@cancelMails user, props.messageId
 		@DB.save props
 
 	@removeMail: (mail) ->

		q.version = @DB.lessThanOrEqualTo Number version if version
		q.when = @DB.lessThanOrEqualTo Number time if time
		q.processed = !! processed if processed isnt null

		Logger.log 'getting mails with query %s', q


		result = result.sortBy 'user'
		result

	@cancelMails: (user, messageId) ->
		scheduledMails = @getMails user, null, null, false, messageId
		modified = while result.hasNext()
			mail.next().processed = 'canceled'

		if modified.length > 0
			@DB.saveBatch modified, false
			@DB.allOk modified
		else
			true

	@storeMail: (user, version, props) ->
		return null if not props or not user or not version
		props.user = user
