You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by Sandeep Sharma <sa...@yahoo.com> on 2002/04/08 16:49:51 UTC
Re: About CharTerminatedInputStream
Hi Serge,
> Have you used any profiling tools to determine this,
> or is this just a
> back-of-the-envelop calculation?
ya initially when i saw the code first time
i have just used a simple application written using
java mail to test it
the reason for my concerned with the code is that,
this the code responsible for receiving mail and hence
ats as a gateway to JAMES
> While implementing only read() and not read(byte[])
> obviously could
> stand to be improved, when I have done stress
> testing in conjuction with
> a profiling tool, I have not found this to consume a
> noticeable
> percentage of CPU.
i wrote a version of the same code with block read and
found significant performance boost
>
> --
> Serge Knystautas
> Loki Technologies - Unstoppable Websites
> http://www.lokitech.com/
>
> Sandeep Sharma wrote:
> > Hi!
> >
> > I have some doubts regarding the effeciency of the
> > CharTerminatedInputStream :
> >
> > Processing every byte of the message will shoot up
> CPU
> > usage like any thing for example if JAMES receive
> a
> > message of 8K then there will be
> >
> > 8 * 1024 = 8192 read() function calls
> >
> > further the overhead of calling read() function
> 8192
> > times + the processing time will consume lots of
> CPU
> > cycles consequently reducing the overall capacity
> of
> > the JAMES to handle mails
> >
> > I would advice JAMES developers to use Transaction
> > Cost Analysis (TRC) method to performance test
> JAMES
> > Mail Server
> >
> > Sandiep
> > CTO Infosoft TechNet Private Limited
> > http://www.infosoftin.com
>
>
> --
> To unsubscribe, e-mail:
> <ma...@jakarta.apache.org>
> For additional commands, e-mail:
> <ma...@jakarta.apache.org>
>
__________________________________________________
Do You Yahoo!?
Yahoo! Tax Center - online filing with TurboTax
http://taxes.yahoo.com/
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: Send email from an application
Posted by tarun <ta...@datainfosys.net>.
i think u can go for rfc's fpr smtp
anyway basic commands are
like
connecting to SMTP ports and using
HELO etc
u can check the list of commands by using HELP
regards
tarun
*************************************************
Tarundeep Singh Kalra
Project Leader(Server Side Solutions)
Data Infosys Ltd.
Development Center
D-47 Hanuman Nagar
Vaishali Nagar
Jaipur
Raj(INDIA)
Ph:(091)-0141-245039,245040.
Fax:- (091)-0141-703712
visit us at www.datainfosys.com
*************************************************
----- Original Message -----
From: "Thomas Singer" <th...@regnis.de>
To: "James Developers List" <ja...@jakarta.apache.org>
Sent: Sunday, April 14, 2002 10:13 PM
Subject: Re: Send email from an application
> Thank you very much. Any idea, where I can find the basic SMTP commands in
> James?
>
> Best regards,
> Tom
>
>
> At 23:00 08.04.2002 -0700, you wrote:
> >Hi! Thomas
> >
> >I believe that u want to send mail directly (without
> >any dependancy on any kind of middleware servers like
> >SMTP or DNS)
> >
> >To avoid SMTP server & JAVA MAIL
> >to avoid use of SMTP server u can write very small
> >program (may be in Java) that implements basic SMTP
> >commands and connects connects directly to the
> >recipients MX host
> >
> >To avoid DNS
> >i believe that ur support team members e-mail accounts
> >are on ur own server and u know the IP of ur SMTP
> >server. if this is the case u don't need DNS server to
> >resolve MX host
> >
> >Regards
> >Sandiep U. Sharma
> >http://www.infosoftin.com
>
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>
>
>
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: Send email from an application
Posted by Sandeep Sharma <sa...@yahoo.com>.
Hi, Tom
for ur Convenience u can use the code below
import java.util.*;
import java.net.*;
import java.io.*;
public class SMTPSender
{
/**
* Hashtable will hold the rejected recipients
addresses
*/
Hashtable htRejectedRelay = new Hashtable();
/**
* Send message to destination smtphost
* @author Sandiep U. Sharma
(http://www.infosoftin.com)
* @smtphost: SMTP Host address
* @From: Sender email address
* @vt: Vector containing recipients e-mail addresses
* @mmess: Byte array containing message (include
<CRLF>.<CRLF> characters)
*/
public void sendMessage(String smtphost,String From,
Vector vt, byte[] mmess)
{
//System.out.println("smtphost:"+smtphost+"
From:"+From+" Rcpt:"+vt.toString());
//System.out.println("Connecting to :"+smtphost);
Socket sk=null;
DataInputStream din=null;
DataOutputStream dout=null;
try {
// connect to smtp host and initialize I/O streams
sk = new Socket(smtphost,25);
System.out.println("Connected");
String strresp;
din = new DataInputStream(sk.getInputStream());
dout = new DataOutputStream(sk.getOutputStream());
strresp = din.readLine();
System.out.println("S:"+strresp);
if (strresp.startsWith("220"))
dout.writeBytes("helo <server>\r\n"); //Replace
server with hostname
else {
System.out.println("Error :"+strresp);
recipientRejected(vt.toString(),strresp);
return;
}
strresp = din.readLine();
System.out.println("S:"+strresp);
if (strresp.startsWith("250"))
{
dout.writeBytes("mail from:<"+From+">\r\n");
}
else {
System.out.println("Error :"+strresp);
recipientRejected(vt.toString(),strresp);
return;
}
strresp = din.readLine();
System.out.println("S:"+strresp);
if (strresp.startsWith("250"))
{
for (int i = 0;i<vt.size();i++)
{
String strrcpt = (String) vt.elementAt(i);
dout.writeBytes("rcpt to:<"+strrcpt+">\r\n");
strresp = din.readLine();
//System.out.println("S:"+strresp);
if (!strresp.startsWith("250")) {
recipientRejected(strrcpt,strresp);
}
}
}
else
{
System.out.println("Error :"+strresp);
recipientRejected(vt.toString(),strresp);
return;
}
dout.writeBytes("data\r\n");
strresp = din.readLine();
System.out.println("S:"+strresp);
if (strresp.startsWith("354"))
{
dout.write(mmess);
}
else {
System.out.println("Error :"+strresp);
recipientRejected(vt.toString(),strresp);
return;
}
strresp = din.readLine();
System.out.println("S:"+strresp);
dout.writeBytes("quit\r\n");
} catch (Exception ioe) {
System.out.println("I/O error while relaying
mail:"+ioe.toString());
recipientRejected(vt.toString(),ioe.getMessage());
return;
}
try {
din.close();
dout.close();
sk.close();
} catch (Exception ioe) {/* log this exception */}
}
private void recipientRejected(String
strrecipient,String strReason)
{
// do somethis here for the rejected relayed
recipients
System.out.println("\t recipient rejected
"+strrecipient);
htRejectedRelay.put(strrecipient,strReason);
}
}
best Regards
Sandiep U. Sharma, CTO Infosoft
www.infosoftin.com
__________________________________________________
Do You Yahoo!?
Yahoo! Tax Center - online filing with TurboTax
http://taxes.yahoo.com/
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: Send email from an application
Posted by Thomas Singer <th...@regnis.de>.
Thank you very much. Any idea, where I can find the basic SMTP commands in
James?
Best regards,
Tom
At 23:00 08.04.2002 -0700, you wrote:
>Hi! Thomas
>
>I believe that u want to send mail directly (without
>any dependancy on any kind of middleware servers like
>SMTP or DNS)
>
>To avoid SMTP server & JAVA MAIL
>to avoid use of SMTP server u can write very small
>program (may be in Java) that implements basic SMTP
>commands and connects connects directly to the
>recipients MX host
>
>To avoid DNS
>i believe that ur support team members e-mail accounts
>are on ur own server and u know the IP of ur SMTP
>server. if this is the case u don't need DNS server to
>resolve MX host
>
>Regards
>Sandiep U. Sharma
>http://www.infosoftin.com
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: About CharTerminatedInputStream
Posted by Sandeep Sharma <sa...@yahoo.com>.
Hi Stephan Schiessling,
Below is the second version of the code in which i
have taken care of some of the issues raised by u
Bye
import java.io.*;
/**
* @author: Sandiep. U. Sharma
*/
public class NewOptTerminatedStream extends
InputStream
{
private InputStream in;
static final byte term[] = {(byte) '\n', (byte)
'.',(byte) '\r',(byte) '\n'};
byte buf[] = new byte[2048]; //allocate buffer
int bcount = -1;
int pos = -1;
boolean cont = true;
int len;
int j=0;
public NewOptTerminatedStream(InputStream in,
char[] terminator) throws Exception
{
//Initialize buffers
this.in = in;
readByteStream();
}
/**
* Readahed a block of data
*/
public void readByteStream() throws IOException
{
len=0;
if (!cont)
{
bcount = -1; pos = -1;
return;
}
bcount = in.read(buf);
int c=0;
if (j>0){c=j;} //If term char is pending for next
block
for (int i = 0;i<bcount;i++)
{
if (term[c] == buf[i])
{
for (j = c;(j<4) && (i < bcount);j++)
{
if (term[j] != buf[i++])
{
j = -1;
break;
}
}
if (j == 4) //End of file found
{
len = i-4;
pos = 0;
if((bcount > len) && (in instanceof
PushbackInputStream))
{
//If in is a PushBackInputStream the unread
extra bytes readed
((PushbackInputStream)in).unread(buf,len,(bcount-len));
}
bcount=len;
cont = false;
System.out.println("End of file reached");
break;
}
} //End of If block
} // End of for loop
if (cont)
{
len = bcount;
pos = 0;
}
}
public int read() throws IOException
{
if ((bcount >0) && (pos < bcount))
{
return buf[pos++];
} else if (!cont || (bcount == -1)) {
return -1;
} else {
this.readByteStream();
return buf[pos++];
}
}
public int read(byte[] b,int off,int len) throws
IOException
{
if (b.length == 0)
return 0;
if ((bcount >0) && (pos < bcount))
{
int curlen = bcount-pos;
if (curlen <= len)
{
System.arraycopy(buf,pos,b,off,curlen);
this.readByteStream();
return curlen;
} else if (curlen > len)
{
curlen = len;
System.arraycopy(buf,pos,b,off,curlen);
pos = pos + curlen-1;
return curlen;
}
} else if (!cont || (bcount == -1)) {
return -1;
}
return -1;
}
}
__________________________________________________
Do You Yahoo!?
Yahoo! Tax Center - online filing with TurboTax
http://taxes.yahoo.com/
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: About CharTerminatedInputStream
Posted by Stephan Schiessling <s...@rapi.com>.
Hi Sandeep Sharma,
Your code has some problems:
1) In the readBlockStream method, you read a whole
block (2048) bytes, but you forgot a loop to test
all occurences of the terminating characters (actually
it is only tested once).
2) No sign of code to test the terminating characters ("\n.\r\n")
between two blocks.
3) OptTerminatedInputStream reads too much bytes from the underlaying InputStream (given
in the constructor). You cannot expect, that the underlaying InputStream
ends with the terminating characters, so that OptTerminatedInputStream may steal
bytes from underlaying InputStream, which are not accessible by other code.
I think this will be a problem, if more than 1 emails are sent in the same stream.
And this is may main concern about your solution here. I mentioned this in an earlier email in this Thread,
in which I sketched a solution to this problem, but at the same time, I think it will
eat um any performance improvements.
Bye,
Stephan
Sandeep Sharma wrote:
> Hi Stephan,
>
> go through the code below
>
> This the first version of the patch for
> CharTerminatedInputStream, this code is just for the
> testing
>
> Also note that i have hardcoded certain things,
> following code also contains a bug (if u try to send
> mails from telnet, however that can be removed easily)
>
> -----------Start of Patch
> public class OptTerminatedStream extends InputStream
> {
> private InputStream in;
> static final byte term[] = {(byte) '\n', (byte)
> '.',(byte) '\r',(byte) '\n'};
> byte buf[] = new byte[2048]; //allocate buffer
> int bcount = -1;
> int pos = -1;
> boolean cont = true;
> //int totalb = 0;
>
> public OptTerminatedStream(InputStream in, char[]
> terminator) throws Exception
> {
> //Initialize buffers
> this.in = in;
> readByteStream();
> }
>
> /**
> * Readahed a block of data
> */
> public void readByteStream() throws IOException
> {
> String line = "";
> int len;
> len=0;
>
> if (!cont)
> {
> bcount = -1;
> pos = -1;
> return;
> }
>
> bcount = in.read(buf);
>
> if (bcount == -1) //if end-of-file reached
> return;
>
> len = bcount;
> pos = 0;
> try
> {
> if (
> buf[len - 4] == term[0] &&
> buf[len - 3] == term[1] &&
> buf[len - 2] == term[2] &&
> buf[len - 1] == term[3]
> )
> {
> cont = false;
> bcount-=4;
> }
> } catch (ArrayIndexOutOfBoundsException aiob){}
> }
>
> public int read() throws IOException
> {
> if ((bcount >0) && (pos < bcount))
> {
> return buf[pos++];
> } else if (!cont || (bcount == -1)) {
> return -1;
> } else {
> this.readByteStream();
> return buf[pos++];
> }
> }
>
> public int read(byte[] b,int off,int len) throws
> IOException
> {
> if (b.length == 0)
> return 0;
>
> if ((bcount >0) && (pos < bcount))
> {
> int curlen = bcount-pos;
> if (curlen <= len)
> {
> System.arraycopy(buf,pos,b,off,curlen);
> this.readByteStream();
> return curlen;
> } else if (curlen > len)
> {
> curlen = len;
> System.arraycopy(buf,pos,b,off,curlen);
> pos = pos + curlen-1;
> return curlen;
> }
> } else if (!cont || (bcount == -1)) {
> return -1;
> }
> return -1;
> }
> }
> ---------------End of Patch
>
> __________________________________________________
> Do You Yahoo!?
> Yahoo! Tax Center - online filing with TurboTax
> http://taxes.yahoo.com/
>
> --
> To unsubscribe, e-mail: <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
>
>
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: About CharTerminatedInputStream
Posted by Sandeep Sharma <sa...@yahoo.com>.
Hi Stephan,
go through the code below
This the first version of the patch for
CharTerminatedInputStream, this code is just for the
testing
Also note that i have hardcoded certain things,
following code also contains a bug (if u try to send
mails from telnet, however that can be removed easily)
-----------Start of Patch
public class OptTerminatedStream extends InputStream
{
private InputStream in;
static final byte term[] = {(byte) '\n', (byte)
'.',(byte) '\r',(byte) '\n'};
byte buf[] = new byte[2048]; //allocate buffer
int bcount = -1;
int pos = -1;
boolean cont = true;
//int totalb = 0;
public OptTerminatedStream(InputStream in, char[]
terminator) throws Exception
{
//Initialize buffers
this.in = in;
readByteStream();
}
/**
* Readahed a block of data
*/
public void readByteStream() throws IOException
{
String line = "";
int len;
len=0;
if (!cont)
{
bcount = -1;
pos = -1;
return;
}
bcount = in.read(buf);
if (bcount == -1) //if end-of-file reached
return;
len = bcount;
pos = 0;
try
{
if (
buf[len - 4] == term[0] &&
buf[len - 3] == term[1] &&
buf[len - 2] == term[2] &&
buf[len - 1] == term[3]
)
{
cont = false;
bcount-=4;
}
} catch (ArrayIndexOutOfBoundsException aiob){}
}
public int read() throws IOException
{
if ((bcount >0) && (pos < bcount))
{
return buf[pos++];
} else if (!cont || (bcount == -1)) {
return -1;
} else {
this.readByteStream();
return buf[pos++];
}
}
public int read(byte[] b,int off,int len) throws
IOException
{
if (b.length == 0)
return 0;
if ((bcount >0) && (pos < bcount))
{
int curlen = bcount-pos;
if (curlen <= len)
{
System.arraycopy(buf,pos,b,off,curlen);
this.readByteStream();
return curlen;
} else if (curlen > len)
{
curlen = len;
System.arraycopy(buf,pos,b,off,curlen);
pos = pos + curlen-1;
return curlen;
}
} else if (!cont || (bcount == -1)) {
return -1;
}
return -1;
}
}
---------------End of Patch
__________________________________________________
Do You Yahoo!?
Yahoo! Tax Center - online filing with TurboTax
http://taxes.yahoo.com/
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: About CharTerminatedInputStream
Posted by Stephan Schiessling <s...@rapi.com>.
Sandeep Sharma wrote:
> Hi Serge,
>
>
>>Have you used any profiling tools to determine this,
>>or is this just a
>>back-of-the-envelop calculation?
>
> ya initially when i saw the code first time
>
> i have just used a simple application written using
> java mail to test it
>
> the reason for my concerned with the code is that,
> this the code responsible for receiving mail and hence
> ats as a gateway to JAMES
>
>
>>While implementing only read() and not read(byte[])
>>obviously could
>>stand to be improved, when I have done stress
>>testing in conjuction with
>>a profiling tool, I have not found this to consume a
>>noticeable
>>percentage of CPU.
>
>
> i wrote a version of the same code with block read and
> found significant performance boost
Then just send a patch for james, so that we can test this code.
Bye,
Stephan Schiessling
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: Send email from an application
Posted by Sandeep Sharma <sa...@yahoo.com>.
Hi! Thomas
I believe that u want to send mail directly (without
any dependancy on any kind of middleware servers like
SMTP or DNS)
To avoid SMTP server & JAVA MAIL
to avoid use of SMTP server u can write very small
program (may be in Java) that implements basic SMTP
commands and connects connects directly to the
recipients MX host
To avoid DNS
i believe that ur support team members e-mail accounts
are on ur own server and u know the IP of ur SMTP
server. if this is the case u don't need DNS server to
resolve MX host
Regards
Sandiep U. Sharma
http://www.infosoftin.com
__________________________________________________
Do You Yahoo!?
Yahoo! Tax Center - online filing with TurboTax
http://taxes.yahoo.com/
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>