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 Oki DZ <ok...@pindad.com> on 2001/10/30 02:42:59 UTC

MailImpl.getSize() (Re: cvs commit: jakarta-james/src/java/org/apache/james/core MailImpl.java)

On 27 Oct 2001 danny@apache.org wrote:
>   diff -u -r1.7 -r1.8
>   --- MailImpl.java	2001/10/26 04:58:47	1.7
>   +++ MailImpl.java	2001/10/27 18:09:20	1.8
>   @@ -138,7 +138,7 @@
>            int size = message.getSize();
>            Enumeration e = message.getAllHeaderLines();
>            while (e.hasMoreElements()) {
>   -            size += ((Header)e.nextElement()).toString().length();
>   +            size += ((String)e.nextElement()).length();
>            }
>            return size;
>        }

In MimeMessageJDBCSource.java:
 public synchronized long getSize() throws IOException {
        if (retrieveMessageBodySizeSQL == null) {
            //There was no SQL statement for this repository... figure it
out the hard way
            return super.getSize();
        }

        try {
            Connection conn = repository.getConnection();

            PreparedStatement retrieveMessageSize =
conn.prepareStatement(retrieveMessageBodySizeSQL);
            retrieveMessageSize.setString(1, key);
            retrieveMessageSize.setString(2, repository.repositoryName);
            ResultSet rsRetrieveMessageSize =
retrieveMessageSize.executeQuery();

            if (!rsRetrieveMessageSize.next()) {
                throw new IOException("Could not find message");
            }

            long size = rsRetrieveMessageSize.getLong(1);
//...

AFAIK, the messages stored in message_body field of James.Message are
always including the header lines; so I believe that MailImpl.getSize() 
and MimeMessageWrapper.getSize() (in which MimeMessageWrapper has a
MimeMessageJDBCSource as one of its fields; if you use a db repository) 
would return different numbers. Is this all right? 

I don't think I've ever used MailImpl.getSize(); to get a message size, I
always use MimeMessage message = MailImpl.getMessage(); int size =
message.getSize(). I use a db repository, so I always get whatever
length(message_body) returned by MySQL. But I believe that
MailImpl.getSize()  and MimeMessageWrapper.getSize() should return the
same number, right? No matter what kind of mail repository you use.

Oki



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: MailImpl.getSize() (Re: cvs commit: jakarta-james/src/java/org/apache/james/core MailImpl.java)

Posted by Oki DZ <ok...@pindad.com>.
On Tue, 30 Oct 2001, Gabriel Bucher wrote:
> I think, the getSize() from MimeMessageYYYSource get back the wrong size! The 
> class MimeMessageWrapper extends from MimeMessage. If you read the JavaDoc from 
> JavaMail then you can see... that MimeMessage.getSize() is only the size of the 
> 'Message content'! MimeMessageWrapper.getSize() should get back the same as 
> MimeMessage.getSize()! 

Yes, JavaMail says that MimeMessage.getSize() returns the length of the
message content. But in the abstract MimeMessageSource, the root of
MimeMessageYYYSource, getSize() returns the message length (header +
content length). So does all other MimeMessage source classes.

> If you take a look into the MimeMessageInputStreamSource,  
> you calculate the size of the hole message (headers + content).

I didn't change how the class supposed to be working; I just added some
features.

> I think, the most time, you are more interesting in the size of Headers + 
> Content (MailImpl.getSize()) (for LIST/STAT) instead of only the size of the 
> content (MimeMessageWrapper.getSize()).

Yes. 
I believe that's why the MimeMessageSource.getSize() returns the
message length.
 
> I think, there are a couple of more problems in the classes MailImpl, 
> MimeMessageWrapper, ....

I believe there's no problem, because nobody uses MailImpl.getSize() :-)
Anyway, I think MailImpl should check what kind of MimeMessage it is
holding; if it is a MimeMessage (created by new MimeMessage()), then it
should add the headers' length; if it is one of the MimeMessage sources,
just get the source and invoke its getSize() method.

Oki




--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: MailImpl.getSize() (Re: cvs commit: jakarta-james/src/java/org/apache/james/core MailImpl.java)

Posted by Oki DZ <ok...@pindad.com>.
On Tue, 30 Oct 2001, Gabriel Bucher wrote:
> I think, the getSize() from MimeMessageYYYSource get back the wrong size! The 
> class MimeMessageWrapper extends from MimeMessage. If you read the JavaDoc from 
> JavaMail then you can see... that MimeMessage.getSize() is only the size of the 
> 'Message content'! MimeMessageWrapper.getSize() should get back the same as 
> MimeMessage.getSize()! 

Yes, JavaMail says that MimeMessage.getSize() returns the length of the
message content. But in the abstract MimeMessageSource, the root of
MimeMessageYYYSource, getSize() returns the message length (header +
content length). So does all other MimeMessage source classes.

> If you take a look into the MimeMessageInputStreamSource,  
> you calculate the size of the hole message (headers + content).

I didn't change how the class supposed to be working; I just added some
features.

> I think, the most time, you are more interesting in the size of Headers + 
> Content (MailImpl.getSize()) (for LIST/STAT) instead of only the size of the 
> content (MimeMessageWrapper.getSize()).

Yes. 
I believe that's why the MimeMessageSource.getSize() returns the
message length.
 
> I think, there are a couple of more problems in the classes MailImpl, 
> MimeMessageWrapper, ....

I believe there's no problem, because nobody uses MailImpl.getSize() :-)
Anyway, I think MailImpl should check what kind of MimeMessage it is
holding; if it is a MimeMessage (created by new MimeMessage()), then it
should add the headers' length; if it is one of the MimeMessage sources,
just get the source and invoke its getSize() method.

Oki



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: MailImpl.getSize() (Re: cvs commit: jakarta-james/src/java/org/apache/james/core MailImpl.java)

Posted by Gabriel Bucher <ga...@razor.ch>.
Quoting Oki DZ <ok...@pindad.com>:

> On 27 Oct 2001 danny@apache.org wrote:
> >   diff -u -r1.7 -r1.8
> >   --- MailImpl.java	2001/10/26 04:58:47	1.7
> >   +++ MailImpl.java	2001/10/27 18:09:20	1.8
> >   @@ -138,7 +138,7 @@
> >            int size = message.getSize();
> >            Enumeration e = message.getAllHeaderLines();
> >            while (e.hasMoreElements()) {
> >   -            size +=
> ((Header)e.nextElement()).toString().length();
> >   +            size += ((String)e.nextElement()).length();
> >            }
> >            return size;
> >        }
> 
> In MimeMessageJDBCSource.java:
>  public synchronized long getSize() throws IOException {
>         if (retrieveMessageBodySizeSQL == null) {
>             //There was no SQL statement for this repository... figure
> it
> out the hard way
>             return super.getSize();
>         }
> 
>         try {
>             Connection conn = repository.getConnection();
> 
>             PreparedStatement retrieveMessageSize =
> conn.prepareStatement(retrieveMessageBodySizeSQL);
>             retrieveMessageSize.setString(1, key);
>             retrieveMessageSize.setString(2,
> repository.repositoryName);
>             ResultSet rsRetrieveMessageSize =
> retrieveMessageSize.executeQuery();
> 
>             if (!rsRetrieveMessageSize.next()) {
>                 throw new IOException("Could not find message");
>             }
> 
>             long size = rsRetrieveMessageSize.getLong(1);
> //...
> 
> AFAIK, the messages stored in message_body field of James.Message are
> always including the header lines; so I believe that MailImpl.getSize()
If I understand James right, MailImpl.getSize() should be 'Message Content' + 
'Message Headers'!
> 
> and MimeMessageWrapper.getSize() (in which MimeMessageWrapper has a
> MimeMessageJDBCSource as one of its fields; if you use a db repository)
I think, the getSize() from MimeMessageYYYSource get back the wrong size! The 
class MimeMessageWrapper extends from MimeMessage. If you read the JavaDoc from 
JavaMail then you can see... that MimeMessage.getSize() is only the size of the 
'Message content'! MimeMessageWrapper.getSize() should get back the same as 
MimeMessage.getSize()! If you take a look into the MimeMessageInputStreamSource,  
you calculate the size of the hole message (headers + content).

> 
> would return different numbers. Is this all right? 
> 
> I don't think I've ever used MailImpl.getSize(); to get a message size,
> I
> always use MimeMessage message = MailImpl.getMessage(); int size =
> message.getSize(). I use a db repository, so I always get whatever
> length(message_body) returned by MySQL. But I believe that
> MailImpl.getSize()  and MimeMessageWrapper.getSize() should return the
> same number, right? No matter what kind of mail repository you use.
Both sould return the same size, thats correct!
I think, the most time, you are more interesting in the size of Headers + 
Content (MailImpl.getSize()) (for LIST/STAT) instead of only the size of the 
content (MimeMessageWrapper.getSize()).

I think, there are a couple of more problems in the classes MailImpl, 
MimeMessageWrapper, ....
I'm working on a couple of JUnit TestCases for this!

Cheers,
Buchi

> 
> Oki
> 
> 
> 
> --
> 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>