This concept helps you to manage your mailbox.
You can use it like a handler or a concept.
This example will show how you can use the mailbox concept like a concept.
$expr = Simplex.create("*nextra*")
#creating the mailbox concept, the URL shows your mailbox file
#can use similarly the file:// protocoll
$mb = Mbox.create("mbox://var/mail/spool/atech")
#if you have a RFC822 compatible message stored in $msg
#you can add to your mailbox
$mb.addMessage($msg)
#checking my mails
print "My mails in mbox: " + $mb.check
#let show the message ids (all)
print "IDs: " + $mb.getID
#let show the message ids matching expression $expr
print "Filtered IDs: " + $mb.getID($expr)
#my first message id
$id = $mb.getID/1
#I'm curious, I want to see my first message header
$heads = $mb.getHeader($id)
print $heads/1.toXML
#all the headers and headers matching my $expr expression
$heads = $mb.getHeader("")
$heads = $mb.getHeader($expr)
#my first message
$mails = $mb.getMessage($id)
print $mails/1.toXML
#all the messages and messages matching my $expr expression
$mails = $mb.getMessage("")
$mails = $mb.getMessage($expr)
#my first message is ugly, I will delete it
$mb.delete($id)
#all my messages are ugly :)
#take care all messages will be deleted!
$mb.DeleteAll
#I want to know what mailbox I use?
print "My mailbox is: " + $mb.getResourceURI
#I want to know where my message coming from?
print "The Message mailbox is: " + $mb.getMessage($id)/1.getResourceURI
#the message original form (RFC822 message source)
print "Orig Message: " + $mb.getMessage($id)/1.toTXT
This example will show how you can use the mailbox concept like a handler.
Can use in URL an URL query (..?cmd=getHeader&requests=5) or similarly
an options argument after from ("cmd"="getHeader", "requests"=5)
#if you have a RFC822 compatible message stored in $msg
#you can add to your mailbox
$msg to "mbox://var/spool/mail/atech"
#checking my mails in two ways, of course use only one
$mb from "mbox://var/spool/mail/atech?cmd=check"
$mb from "mbox://var/spool/mail/atech" options "cmd"="check"
print "Mails in mbox: " + $mb
#let show the message ids (all)
$ids from "mbox://var/spool//mail/atech" options "cmd"="getID"
print $ids
#get the message ids matching expression $expr
$mb from "mbox://var/spool//mail/atech" options "cmd"="getID", "filter"=$expr
#get the message headers
$mb from "mbox://var/spool//mail/atech" options "cmd"="getHeaders", "id"=""
#get the message header for specified id
$ids from "mbox://var/spool//mail/atech" options "cmd"="getID"
$heads from "mbox://var/spool//mail/atech" options "cmd"="getHeaders", "id"=$ids/1
print $heads/1.toXML
#get the first five messages
$msgs from "mbox://var/spool//mail/atech" options "cmd"="getMessage","requests"=5
#delete the specified message
$heads from "mbox://var/spool//mail/atech" options "cmd"="delete", "id"=$ids/1
#delete all my messages
$heads from "mbox://var/spool//mail/atech" options "cmd"="deleteAll"
Methods inherited from: Concept
| cloneConcept, extendsConcept, fromXML, getAllInheritedConcepts, getConceptAttribute, getConceptAttributeField, getConceptAttributeFields, getConceptAttributes, getConceptConstructors, getConceptElement, getConceptElementField, getConceptElementFields, getConceptElements, getConceptLabel, getConceptMethod, getConceptMethods, getConceptOperators, getConceptType, getErrorHandler, getInheritedConcepts, getResourceURI, hasConceptAttribute, hasConceptElement, hasConceptMethod, hasPath, isHidden, loadContent, setConceptLabel, setErrorHandler, setHidden, setShowEmpty, showEmpty, toTXT, toXML, setResourceURI |
|
| Exceptions: |
badURLException :
(Error) | If the URL to the mBox isn't valid. |
Creating the concept with a named URL string
Looking if your URL protocol is accepted.
print Mbox.acceptsURI("mbox://home/guest/nsmail/Inbox")
-- the result is --
true
| Exceptions: |
connectionException :
(Error) | If unable to connect to specified XML database. |
Opens the mbox connection.
| Exceptions: |
mboxOperationException :
(Error) | If unable to add message to the mailbox |
Adds (appends) your message to mailbox, if the mailbox isn't exists it will be created.
$inbox = Mbox.create("mbox://home/guest/nsmail/Inbox")
$friends = Mbox.create("mbox://home/guest/nsmail/Friends")
print $friends.check
$msg = $inbox.getMessage(Simplex.create("*Jim*"))
while ($msg@hasNext) do [
$friends.addMessage($msg.next)
]
print $friends.check
-- the result is --
3
8
| Exceptions: |
mboxOperationException :
(Error) | If unable to check the mailbox |
Checking the mailbox and returns the number of messages
$mbx = Mbox.create("mbox://home/guest/nsmail/Inbox")
print $mbx.check
-- the result is --
12
| Exceptions: |
mboxOperationException :
(Error) | If unable to delete the message |
Delete message with named id.
$mbx = Mbox.create("mbox://home/guest/nsmail/Inbox")
print $mbx.getID
$mbx.delete($mbx.getID(Simplex.create("*outblaze*"))/1/)
print $mbx.getID
-- the result is --
<200204090516.g395G5207064@ns.compila2.net>
<200202072116.g17LGMP08201@www.avidgamers.com>
<20011217100619.17459.qmail@mta4-3.us4.outblaze.com>
<20010921161121.03483.03184945@newman-m02.aol.com>
<200204090516.g395G5207064@ns.compila2.net>
<200202072116.g17LGMP08201@www.avidgamers.com>
<20010921161121.03483.03184945@newman-m02.aol.com>
| Exceptions: |
mboxOperationException :
(Error) | If unable to delete the all messages |
Deletes all messages.
$mbx = Mbox.create("mbox://home/guest/nsmail/Inbox")
$mbx.check
$mbx.deleteAll
$mbx.check
-- the result is --
12
0
| Exceptions: |
mboxOperationException :
(Error) | If unable to get the message headers |
Gets the named message header, if the parameter is empty will returns all the messages.
$mbx = Mbox.create("mbox://home/guest/nsmail/Inbox")
$msgID = $mbx.getID(Simplex.create("*outblaze*"))
print $mbx.getHeader($msgID)
-- the result is --
emx:Message
xmlns:rfc822: URN:ietf:params:rfc822: xmlns:emx: URN:ietf:params:email-xml:
rfc822:subject
TEST
rfc822:message-id
<20011217100619.17459.qmail@mta4-3.us4.outblaze.com>
emx:part
rfc822:content-type
charset: US-ASCII
TEXT/PLAIN
| Exceptions: |
mboxOperationException :
(Error) | If unable to get the message headers |
Gets the message headers matching to the expression given as parameter.
$mbx = Mbox.create("mbox://home/guest/nsmail/Inbox")
print $mbx.getHeader(Simplex.create("*outblaze*"))
-- the result is --
emx:Message
xmlns:rfc822: URN:ietf:params:rfc822: xmlns:emx: URN:ietf:params:email-xml:
rfc822:subject
TEST
rfc822:message-id
<20011217100619.17459.qmail@mta4-3.us4.outblaze.com>
emx:part
rfc822:content-type
charset: US-ASCII
TEXT/PLAIN
| Exceptions: |
mboxOperationException :
(Error) | If unable to get the message ids |
Gets the messages id.
$mbx = Mbox.create("mbox://home/guest/nsmail/Inbox")
print $mbx.getID
-- the result is --
<200204090516.g395G5207064@ns.compila2.net>
<200202072116.g17LGMP08201@www.avidgamers.com>
<20011217100619.17459.qmail@mta4-3.us4.outblaze.com>
<20010921161121.03483.03184945@newman-m02.aol.com>
| Exceptions: |
mboxOperationException :
(Error) | If unable to get the message ids |
Gets the ids matching to the expression given as parameter.
$mbx = Mbox.create("mbox://home/guest/nsmail/Inbox")
print $mbx.getID(Simplex.create("*outblaze*"))
-- the result is --
<20011217100619.17459.qmail@mta4-3.us4.outblaze.com>
| Exceptions: |
mboxOperationException :
(Error) | If unable to get the messages |
Gets the messages matching to the expression given as parameter.
$mbx = Mbox.create("mbox://home/guest/nsmail/Inbox")
print $mbx.getMessage(Simplex.create("*Hi!*"))
-- the result is --
emx:Message
xmlns:rfc822: URN:ietf:params:rfc822: xmlns:emx: URN:ietf:params:email-xml:
rfc822:subject
TEST
rfc822:message-id
<20011217100619.17459.qmail@mta4-3.us4.outblaze.com>
emx:part
rfc822:content-type
charset: US-ASCII
TEXT/PLAIN
emx:BodyPart
Hi! This is a test mail.
| Exceptions: |
mboxOperationException :
(Error) | If unable to get the messages |
Gets the named messages, if the parameter is empty will returns all the messages.
$mbx = Mbox.create("mbox://home/guest/nsmail/Inbox")
$msgID = $mbx.getID(Simplex.create("*outblaze*"))
print $mbx.getMessage($msgID)
-- the result is --
emx:Message
xmlns:rfc822: URN:ietf:params:rfc822: xmlns:emx: URN:ietf:params:email-xml:
rfc822:subject
TEST
rfc822:message-id
<20011217100619.17459.qmail@mta4-3.us4.outblaze.com>
emx:part
rfc822:content-type
charset: US-ASCII
TEXT/PLAIN
emx:BodyPart
Hi! This is a test mail.