Access DB via mailet

2015-03-03 Thread Hassan Latif
Hello,

This maybe a very basic question as I'm new to James. I'm trying to figure
out what are the options of accessing a database through a custom mailet
and what are the caveats. For my scenario I need to save the headers of an
incoming email. I can also prepare a document providing the details of
accessing DB from the mailet for the benefits of others if someone can
point me in the right direction.

Thanks.

Hassan


AW: Access DB via mailet [unsigned]

2015-03-03 Thread Bernd Waibel
Hello Hassan,

if you are writing a mailet, you are just inside a java class with full access 
to the mail object. 
So you could do what you like in accessing a database.
There is no limit for accessing a database from your class, but I think there 
is no direct support for predefined database objects or something like that.

I could only offer hints from our implementation.
We are using James v2.3.2, together with a database (postgres, but that does 
not matter).
We implemented this independent from James, handling all thing by our own code. 
    

Just few hints:
- Be failsave. The database could be offline and all that worse things. You 
need to handle that.
- Be failsave. The mail object may not be as defined by RFC, fields may missing 
(like from or to). Many spam mails are far away from mail standards. Expect 
parsing errors every time.
- If you throw an exception, or your database clients does, or java mail does, 
the mail will fail.
Failed mails will not be sent and will be stored to the error processor.
- Configure your db access. We used JPA for database access. JPA has own 
properties for configuring the database access (user, password and so on). We 
used eclipselink, for accessing and defining JPA. You may have a look at that.
- Your database client jar (eg. postgresql-jdbc3-9.1.jar) should reside in 
/var/james-2.3.2/apps/james/SAR-INF/lib/ for 2.3.2. (not sure for 3.x).
- Think about what will happen for database schema updates. At the time you 
will deliver the next version of your software, you may need to update your 
database schema. We use Liquibase for that. You may have a look at that.

We configured the database access inside the config.xml, like:
mailet match=All class=myMailet

jpa-javax.persistence.jdbc.urljdbc:postgresql:myUsername/jpa-javax.persistence.jdbc.url

jpa-javax.persistence.jdbc.usermyPass/jpa-javax.persistence.jdbc.user

/mailet

Most of that hints are independend from James. Every mail project using a 
database may have this hints in mind.


Good look!
Bernd

-Ursprüngliche Nachricht-
Von: Hassan Latif [mailto:hassan.la...@gmail.com] 
Gesendet: Dienstag, 3. März 2015 09:48
An: James Users List
Betreff: Access DB via mailet

Hello,

This maybe a very basic question as I'm new to James. I'm trying to figure out 
what are the options of accessing a database through a custom mailet and what 
are the caveats. For my scenario I need to save the headers of an incoming 
email. I can also prepare a document providing the details of accessing DB from 
the mailet for the benefits of others if someone can point me in the right 
direction.

Thanks.

Hassan


Thunderbird Losing UIDs in Folders

2015-03-03 Thread Jerry Malcolm
I use JAMES 3 b5 with a relatively large mail IMAP database (500K mail 
items) across several accounts.  Most of my clients are using 
Thunderbird.  The problem I'm seeing may very likely be a Thunderbird 
problem.  But I'm just curious what might be going on. Once every few 
days, I'll go to one of the folders in Thunderbird that I have been 
accessing regularly and try to open a mail item.  I get a msg from 
Thunderbird that says something like Mail Server responded that UID is 
invalid.  From this point on, all mail in that folder is 
inaccessible.   I found that the way to fix it is to go the folder 
properties in Thunderbird and click Repair Folder. This basically 
wipes the folder contents and re-downloads the folder contents from 
James.  Everything is good again until it happens a day or so later on 
the same folder or another folder.  I have Thunderbird on several 
computers.  This consistently occurs on all instances of Thunderbird.


This is by far not a catastrophic problem. But it is a pain.  I'm just 
curious if anyone else is seeing this.  I'm pretty familiar with the 
inner workings of James 3 and the James 3 database structure.  Can 
someone give me a quick explanation of how the folder UIDs are 
generated.  Any idea why the UID would become invalid (unless 
Thunderbird just decided to start sending totally corrupted UIDs)?  
Finally, is there some quick debug logging parm I can enable the next 
time this happens just so I can get a better idea of what invalid UID is 
being sent and what James thinks about that uid?  Even it is totally a 
Mozilla problem, I'd like to arm myself with some good trace data to 
take to Mozilla.


Thanks for any assistance you can provide.

Jerry

-
To unsubscribe, e-mail: server-user-unsubscr...@james.apache.org
For additional commands, e-mail: server-user-h...@james.apache.org



Re: Thunderbird Losing UIDs in Folders

2015-03-03 Thread Jerry Malcolm
Thanks for the quick response, Kurt.  I guess I'll start prowling the 
T-bird forums and see if there's any talk about it there.


Jerry

On 3/3/2015 10:38 AM, Kurt Harders wrote:

Hi Jerry,
i had the same problem with Thunderbird (and some others like sometimes
not opening mail with attachment). This class of problems happens with
e.g. dovecot imap server too, and its a pure Thunderbird problem. Since
i switch to Linux using evolution i never had such problems. The
difference seems to be the amount of buffered/locally stored
information.

Regards, Kurt

Am Dienstag, den 03.03.2015, 10:21 -0600 schrieb Jerry Malcolm:

I use JAMES 3 b5 with a relatively large mail IMAP database (500K mail
items) across several accounts.  Most of my clients are using
Thunderbird.  The problem I'm seeing may very likely be a Thunderbird
problem.  But I'm just curious what might be going on. Once every few
days, I'll go to one of the folders in Thunderbird that I have been
accessing regularly and try to open a mail item.  I get a msg from
Thunderbird that says something like Mail Server responded that UID is
invalid.  From this point on, all mail in that folder is
inaccessible.   I found that the way to fix it is to go the folder
properties in Thunderbird and click Repair Folder. This basically
wipes the folder contents and re-downloads the folder contents from
James.  Everything is good again until it happens a day or so later on
the same folder or another folder.  I have Thunderbird on several
computers.  This consistently occurs on all instances of Thunderbird.

This is by far not a catastrophic problem. But it is a pain.  I'm just
curious if anyone else is seeing this.  I'm pretty familiar with the
inner workings of James 3 and the James 3 database structure.  Can
someone give me a quick explanation of how the folder UIDs are
generated.  Any idea why the UID would become invalid (unless
Thunderbird just decided to start sending totally corrupted UIDs)?
Finally, is there some quick debug logging parm I can enable the next
time this happens just so I can get a better idea of what invalid UID is
being sent and what James thinks about that uid?  Even it is totally a
Mozilla problem, I'd like to arm myself with some good trace data to
take to Mozilla.

Thanks for any assistance you can provide.

Jerry

-
To unsubscribe, e-mail: server-user-unsubscr...@james.apache.org
For additional commands, e-mail: server-user-h...@james.apache.org




-
To unsubscribe, e-mail: server-user-unsubscr...@james.apache.org
For additional commands, e-mail: server-user-h...@james.apache.org



Re: Thunderbird Losing UIDs in Folders

2015-03-03 Thread Kurt Harders
Hi Jerry,

good luck :-). Please post any valuable solution in this thread. I still
have customers using windows.

Regards, Kurt

Am Dienstag, den 03.03.2015, 10:48 -0600 schrieb Jerry Malcolm:
 Thanks for the quick response, Kurt.  I guess I'll start prowling the 
 T-bird forums and see if there's any talk about it there.
 
 Jerry
 
 On 3/3/2015 10:38 AM, Kurt Harders wrote:
  Hi Jerry,
  i had the same problem with Thunderbird (and some others like sometimes
  not opening mail with attachment). This class of problems happens with
  e.g. dovecot imap server too, and its a pure Thunderbird problem. Since
  i switch to Linux using evolution i never had such problems. The
  difference seems to be the amount of buffered/locally stored
  information.
 
  Regards, Kurt
 
  Am Dienstag, den 03.03.2015, 10:21 -0600 schrieb Jerry Malcolm:
  I use JAMES 3 b5 with a relatively large mail IMAP database (500K mail
  items) across several accounts.  Most of my clients are using
  Thunderbird.  The problem I'm seeing may very likely be a Thunderbird
  problem.  But I'm just curious what might be going on. Once every few
  days, I'll go to one of the folders in Thunderbird that I have been
  accessing regularly and try to open a mail item.  I get a msg from
  Thunderbird that says something like Mail Server responded that UID is
  invalid.  From this point on, all mail in that folder is
  inaccessible.   I found that the way to fix it is to go the folder
  properties in Thunderbird and click Repair Folder. This basically
  wipes the folder contents and re-downloads the folder contents from
  James.  Everything is good again until it happens a day or so later on
  the same folder or another folder.  I have Thunderbird on several
  computers.  This consistently occurs on all instances of Thunderbird.
 
  This is by far not a catastrophic problem. But it is a pain.  I'm just
  curious if anyone else is seeing this.  I'm pretty familiar with the
  inner workings of James 3 and the James 3 database structure.  Can
  someone give me a quick explanation of how the folder UIDs are
  generated.  Any idea why the UID would become invalid (unless
  Thunderbird just decided to start sending totally corrupted UIDs)?
  Finally, is there some quick debug logging parm I can enable the next
  time this happens just so I can get a better idea of what invalid UID is
  being sent and what James thinks about that uid?  Even it is totally a
  Mozilla problem, I'd like to arm myself with some good trace data to
  take to Mozilla.
 
  Thanks for any assistance you can provide.
 
  Jerry
 
  -
  To unsubscribe, e-mail: server-user-unsubscr...@james.apache.org
  For additional commands, e-mail: server-user-h...@james.apache.org
 
 
 
 -
 To unsubscribe, e-mail: server-user-unsubscr...@james.apache.org
 For additional commands, e-mail: server-user-h...@james.apache.org
 

-- 
KHTronik - Kurt Harders 
Elektronik, Softwareentwicklung, Opensource-Beratung 
Leimbacher Str. 36 
42281 Wuppertal 

T +49 202  2 50 11 64 
F +49 202  2 50 11 65 
M +49 171  8 36 82 33 





-
To unsubscribe, e-mail: server-user-unsubscr...@james.apache.org
For additional commands, e-mail: server-user-h...@james.apache.org



Re: James 3 b4 HELO Override Not Working?

2015-03-03 Thread Robert Munn
ok
On Mar 1, 2015 12:51 AM, Eric Charles e...@apache.org wrote:

 Can you open a JIRA and upload your patches there?

 On 10/28/2014 12:11 AM, Robert Munn wrote:
  OK, I made an Eclipse patch for the RemoteDelivery issue. I also made a
 patch for a mod I made to ReadOnlyUsersLDAPRespository.java that filters
 LDAP users by an additional filter string specified in the ldap conf file.
 Details, and patches, available on my blog:
 
 
 http://blog.bonnydoonmedia.com/post.cfm/patches-for-apache-james-mail-server-3-0-beta5
 
 
 
  On Oct 27, 2014, at 2:05 PM, Robert Munn cfmuns...@gmail.com wrote:
 
  Forgot one thing. Just above the try{} block, Transport transport is
 defined. I changed it to this:
 
  SMTPTransport transport = null;
 
 
 
  On Oct 27, 2014, at 1:54 PM, Robert Munn cfmuns...@gmail.com wrote:
 
  Here is my code. Import the SMTPTransport class, and replace this:
 
   transport = session.getTransport(outgoingMailServer);
 
  with this:
 
   transport =  (SMTPTransport) session.getTransport(outgoingMailServer);
   transport.setLocalHost( props.getProperty(mail.smtp.localhost,
 heloName) );
 
  I added:
 
  !-- Set the HELO/EHLO name to use when connectiong to remote
 SMTP-Server --
  mail.smtp.localhostmail.legacyavatar.com
 /mail.smtp.localhost
 
  and I have confirmed that it is being picked up by
 props.getProperty(“mail.smtp.localhost”).
 
 
 
 
  On Oct 27, 2014, at 1:23 PM, Robert Munn cfmuns...@gmail.com wrote:
 
  Great stuff. I got the build working as well. I don’t like the fact
 that we’re forcing it to use SMTPTransport, ruling out using other
 transport providers, but if you look at the section of the code just below
 there, you see this:
 
   // if the transport is a SMTPTransport (from sun) some
   // performance enhancement can be done.
   if (transport.getClass().getName().endsWith(.SMTPTransport)) {
 
  so there is a section that is testing the class and adding extensions
 already. I might wrap the code in a class name check and only call
 setLocalHost() if I find
 org.apache.geronimo.javamail.transport.smtp.SMTPTransport.
 
  Also, you only need to import that class, not the entire
 org.apache.geronimo.javamail.transport.smtp.* package. Better for the
 memory footprint.
 
 
  I will help with jDKIM, I will need to set it up myself. Where to
 start?
 
 
 
  On Oct 27, 2014, at 12:29 PM, Jerry Malcolm techst...@malcolms.com
 wrote:
 
  Well, Robert, you get the prize It works (finally)!
 
  Two changes required to RemoteDelivery mailet:
 
  Add:
  import org.apache.geronimo.javamail.transport.smtp.*;
 
  Right after:
  transport = session.getTransport(outgoingMailServer);
 
  add:
 
 ((org.apache.geronimo.javamail.transport.smtp.SMTPTransport)transport).setLocalHost(
 mail.jwmhosting.com);
 
  or be more generic and get the value from props.
 
  The setLocalHost needs to be right after the object is instantiated
 since the HELO is sent on one of the first calls to transport.
 
  This fixes it (thank you so much for your help).  But Geronimo is
 still not following the spec and honoring the property
 mail.smtp.localhost.  It needs to be fixed in a subsequent release.
 
  Basically everybody using James 3 needs to add this fix to the
 mailet, at least if running on a Windows server.  Or verify through
 mail-tester.com that the HELO is correct.  Going back to the orig
 problem, gmail was not delivering tons of my mail due to this.
 
  Thanks again.
 
  Now anybody offer any help on getting jDKIM working?  I've got
 it implemented and the DNS is set up.  But mail-tester is telling me the
 signature is invalid.  On to the next problem.
 
  Jerry
 
 
 
 
  On 10/27/2014 2:00 PM, Jerry Malcolm wrote:
  The mailet only sees 'transport' which is cast to generic
 javax.mail.Transport.   The localhost methods and connection methods are
 all part of the geronimo impl.  You'll need to cast the transport to the
 geronimo package for the class, then see if you can get the connection
 object from the transport.  Might work.  But non-trivial.  I'll play around
 with that was well.
 
  Jerry
 
  On 10/27/2014 1:41 PM, Robert Munn wrote:
  Here is the base code. Note localHost is a property of the
 MailConnection class. Note also that there is a setLocalHost() method. I am
 going to try setting the localhost property from RemoteDelivery using
 setLocalHost( localHost ).
 
   public String getLocalHost() throws MessagingException {
   if (localHost == null) {
 
   try {
   localHost = InetAddress.getLocalHost().getHostName();
   } catch (UnknownHostException e) {
   // fine, we're misconfigured - ignore
   }
 
   if (localHost == null) {
   localHost = props.getProperty(MAIL_LOCALHOST);
   }
 
   if (localHost == null) {
   localHost = props.getSessionProperty(MAIL_LOCALHOST);
   }
 
   if (localHost == null) {
   throw new 

Re: Access DB via mailet [unsigned]

2015-03-03 Thread Hassan Latif
Hi Bernd,

Thanks a lot for your invaluable advice and hints, they will definitely go
a long away in helping me implementing my project.

We are leaning towards using James 3.0 beta for two primary reasons. One,
it's based on the Spring framework so I assume it could be made scale-able
with some effort. Two, if the James community is planning to roll out a
stable version of James 3.0 in the near future then my team wouldn't want
to miss the bandwagon.

I'm also quite new to the Spring framework, but as per my understanding it
does provide some level of database transaction capabilities, and I was
wondering whether we can utilize those capabilities in the context of the
custom mailet.

Appreciate any thoughts on this.

Thanks.

Hassan



On Tue, Mar 3, 2015 at 1:17 PM, Bernd Waibel bwai...@intarsys.de wrote:

 Hello Hassan,

 if you are writing a mailet, you are just inside a java class with full
 access to the mail object.
 So you could do what you like in accessing a database.
 There is no limit for accessing a database from your class, but I think
 there is no direct support for predefined database objects or something
 like that.

 I could only offer hints from our implementation.
 We are using James v2.3.2, together with a database (postgres, but that
 does not matter).
 We implemented this independent from James, handling all thing by our own
 code.

 Just few hints:
 - Be failsave. The database could be offline and all that worse things.
 You need to handle that.
 - Be failsave. The mail object may not be as defined by RFC, fields may
 missing (like from or to). Many spam mails are far away from mail
 standards. Expect parsing errors every time.
 - If you throw an exception, or your database clients does, or java mail
 does, the mail will fail.
 Failed mails will not be sent and will be stored to the error processor.
 - Configure your db access. We used JPA for database access. JPA has own
 properties for configuring the database access (user, password and so on).
 We used eclipselink, for accessing and defining JPA. You may have a look
 at that.
 - Your database client jar (eg. postgresql-jdbc3-9.1.jar) should reside in
 /var/james-2.3.2/apps/james/SAR-INF/lib/ for 2.3.2. (not sure for 3.x).
 - Think about what will happen for database schema updates. At the time
 you will deliver the next version of your software, you may need to update
 your database schema. We use Liquibase for that. You may have a look at
 that.

 We configured the database access inside the config.xml, like:
 mailet match=All class=myMailet

 jpa-javax.persistence.jdbc.urljdbc:postgresql:myUsername/jpa-javax.persistence.jdbc.url

 jpa-javax.persistence.jdbc.usermyPass/jpa-javax.persistence.jdbc.user
 
 /mailet

 Most of that hints are independend from James. Every mail project using a
 database may have this hints in mind.


 Good look!
 Bernd

 -Ursprüngliche Nachricht-
 Von: Hassan Latif [mailto:hassan.la...@gmail.com]
 Gesendet: Dienstag, 3. März 2015 09:48
 An: James Users List
 Betreff: Access DB via mailet

 Hello,

 This maybe a very basic question as I'm new to James. I'm trying to figure
 out what are the options of accessing a database through a custom mailet
 and what are the caveats. For my scenario I need to save the headers of an
 incoming email. I can also prepare a document providing the details of
 accessing DB from the mailet for the benefits of others if someone can
 point me in the right direction.

 Thanks.

 Hassan