Hi Jeremy,

this is my solution for the pop protocol.
Try to modify your imap.pm like this (I don't know if imap
protocol is so similar than pop protocol):
http://www.mail-archive.com/[email protected]/msg24483.html

Bye.
Francesco Simonini.

----- Original Message -----
Da : "Jeremy Adams" <[email protected]>
A : <[email protected]>
Oggetto : [otrs] Questions regarding access to imap
PostMaster Mail Account
Data : Thu, 05 Mar 2009 12:48:22 -0600

> I have setup the PostMaster Mail Account in system
> administration and can get the system to pull ALL messages
> from the imap account.  Is there a way to have the system
> mark the messages as read and leave them on the server or
> is there a way to have the system check for messages in a
> specific folder only (as opposed to the INBOX)?  The
> rational behind the second folder would be a rule to
> duplicate the message and allow otrs to gen the ticket
> while still retaining a copy of the email for tracking
> purposes.
> 
> Ultimately we would like to keep the messages on the
> server, either in an read state or as a copy located in
> another folder under the account.
> 
> below you should find the code for the IMAP.pm that i have
> changed (noted in color below) to leave the messages in
> the box, but the next time the account it ran it pulls the
> read and unread messages resulting in multiple tickets.
> 
> 
> <<<<<<<<begin IMAP.pm>>>>>>>>>>>>>>>
> # --
> # Kernel/System/MailAccount/IMAP.pm - lib for imap
> accounts # Copyright (C) 2001-2008 OTRS AG,
> http://otrs.org/ # --
> # $Id: IMAP.pm,v 1.5 2008/07/21 11:28:27 mh Exp $
> # --
> # This software comes with ABSOLUTELY NO WARRANTY. For
> details, see # the enclosed file COPYING for license
> information (GPL). If you # did not receive this file, see
> http://www.gnu.org/licenses/gpl-2.0.txt. # --
> 
> package Kernel::System::MailAccount::IMAP;
> 
> use strict;
> use warnings;
> use Net::IMAP::Simple;
> use Kernel::System::PostMaster;
> 
> use vars qw($VERSION);
> $VERSION = qw($Revision: 1.5 $) [1];
> 
> sub new {
>     my ( $Type, %Param ) = @_;
> 
>     # allocate new hash for object
>     my $Self = {%Param};
>     bless( $Self, $Type );
> 
>     # check all needed objects
>     for (qw(DBObject LogObject ConfigObject TimeObject
> MainObject)) {
>         die "Got no $_" if !$Self->{$_};
>     }
> 
>     return $Self;
> }
> 
> sub Fetch {
>     my ( $Self, %Param ) = @_;
> 
>     # check needed stuff
>     for (qw(Login Password Host Trusted QueueID)) {
>         if ( !defined $Param{$_} ) {
>             $Self->{LogObject}->Log( Priority => 'error',
> Message => "$_ not defined!" );
>             return;
>         }
>     }
>     for (qw(Login Password Host)) {
>         if ( !$Param{$_} ) {
>             $Self->{LogObject}->Log( Priority => 'error',
> Message => "Need $_!" );
>             return;
>         }
>     }
> 
>     my $Debug = $Param{Debug} || 0;
>     my $Limit = $Param{Limit} || 5000;
>     my $CMD   = $Param{CMD}   || 0;
> 
>     # MaxEmailSize
>     my $MaxEmailSize =
> $Self->{ConfigObject}->Get('PostMasterMaxEmailSize') ||
> 1024 * 6;
> 
>     # MaxPopEmailSession
>     my $MaxPopEmailSession =
> $Self->{ConfigObject}->Get('PostMasterReconnectMessage')
> || 20;
> 
>     my $Timeout      = 60;
>     my $FetchCounter = 0;
>     my $Reconnect    = 0;
>     my $AuthType     = 'IMAP';
> 
>     # connect to host
>     my $IMAPObject = Net::IMAP::Simple->new( $Param{Host},
> timeout => $Timeout, debug => $Debug );
>     if ( !$IMAPObject ) {
>         $Self->{LogObject}->Log(
>             Priority => 'error',
>             Message  => "$AuthType: Can't connect to
> $Param{Host}",
>         );
>         return;
>     }
> 
>     # authentcation
>     my $Auth = $IMAPObject->login( $Param{Login},
> $Param{Password} );
>     if ( !defined $Auth ) {
>         $IMAPObject->quit();
>         $Self->{LogObject}->Log(
>             Priority => 'error',
>             Message  => "$AuthType: Auth for user
> $Param{Login}/$Param{Host} failed!",
>         );
>         return;
>     }
>     my $NOM = $IMAPObject->select('INBOX') || 0;
> 
>     # fetch messages
>     if ( $NOM > 0 ) {
>         for ( my $Messageno = 1; $Messageno <= $NOM;
> $Messageno++ ) {
> 
>             # check if reconnect is needed
>             if ( ( $FetchCounter + 1 ) >
> $MaxPopEmailSession ) {
>                 $Reconnect = 1;
>                 if ($CMD) {
>                     print "$AuthType: Reconnect Session
> after $MaxPopEmailSession messages...\n";
>                 }
>                 last;
>             }
>             if ($CMD) {
>                 print "$AuthType: Message $Messageno/$NOM
> ($Param{Login}/$Param{Host})\n";
>             }
> 
>             # check message size
>             my $MessageSize = int(
> $IMAPObject->list($Messageno) / 1024 );
>             if ( $MessageSize > $MaxEmailSize ) {
>                 $Self->{LogObject}->Log(
>                     Priority => 'error',
>                     Message =>
>                         "$AuthType: Can't fetch email $NOM
> from $Param{Login}/$Param{Host}. Email to "
>                         . "big ($MessageSize KB - max
> $MaxEmailSize KB)!",
>                 );
>             }
>             else {
> 
>                 # safety protection
>                 $FetchCounter++;
>                 if ( $FetchCounter > 10 && $FetchCounter <
> 25 ) {
>                     if ($CMD) {
>                         print
>                             "$AuthType: Safety protection
> waiting 2 second till processing next mail...\n";
>                     }
>                     sleep 2;
>                 }
>                 elsif ( $FetchCounter > 25 ) {
>                     if ($CMD) {
>                         print
>                             "$AuthType: Safety protection
> waiting 3 seconds till processing next mail...\n";
>                     }
>                     sleep 3;
>                 }
> 
>                 # get message (header and body)
>                 my $Lines            =
> $IMAPObject->get($Messageno);
>                 my $PostMasterObject =
> Kernel::System::PostMaster->new(
>                     %{$Self},
>                     Email   => $Lines,
>                     Trusted => $Param{Trusted} || 0,
>                     Debug   => $Debug,
>                 );
>                 my @Return = $PostMasterObject->Run(
> QueueID => $Param{QueueID} || 0 );
>                 if ( !$Return[0] ) {
>                     my $Lines =
> $IMAPObject->get($Messageno);
>                     my $File = $Self->_ProcessFailed(
> Email => $Lines );
>                     $Self->{LogObject}->Log(
>                         Priority => 'error',
>                         Message  => "$AuthType: Can't
> process mail, see log sub system ("
>                             . "$File, report it on
> http://bugs.otrs.org/)!",
>                     );
>                 }
>                 undef $PostMasterObject;
> 
>  # mark email to delete if it got processed
> # the next line in this script was commeted out so that
> the scrip will  #leave read messgaes in the inbox of the
> IMAP account after the scrip  #scrapes the mail account   
>            
>             # $IMAPObject->delete($Messageno);
> 
>                 # check limit
>                 $Self->{Limit}++;
>                 if ( $Self->{Limit} >= $Limit ) {
>                     $Reconnect = 0;
>                     last;
>                 }
>             }
>             if ($CMD) {
>                 print "\n";
>             }
>         }
>     }
>     else {
>         if ($CMD) {
>             print "$AuthType: No messages
> ($Param{Login}/$Param{Host})\n";
>         }
>     }
> 
>     # log status
>     if ( $Debug > 0 || $FetchCounter ) {
>         $Self->{LogObject}->Log(
>             Priority => 'notice',
>             Message => "$AuthType: Fetched $FetchCounter
> email(s) from $Param{Login}/$Param{Host}.",
>         );
>     }
>     $IMAPObject->expunge_mailbox('INBOX');
>     $IMAPObject->quit();
>     if ($CMD) {
>         print "$AuthType: Connection to $Param{Host}
> closed.\n\n";
>     }
> 
>     # fetch again if still messages on the account
>     if ($Reconnect) {
>         $Self->Fetch(%Param);
>     }
>     return 1;
> }
> 
> sub _ProcessFailed {
>     my ( $Self, %Param ) = @_;
> 
>     # check needed stuff
>     for (qw(Email)) {
>         if ( !defined $Param{$_} ) {
>             $Self->{LogObject}->Log( Priority => 'error',
> Message => "$_ not defined!" );
>             return;
>         }
>     }
> 
>     # get content of email
>     my $Content;
>     for my $Line ( @{ $Param{Email} } ) {
>         $Content .= $Line;
>     }
> 
>     my $Home = $Self->{ConfigObject}->Get('Home') .
> '/var/spool/';
>     my $MD5  = $Self->{MainObject}->MD5sum(
>         String => \$Content,
>     );
>     my $Location = $Home . 'problem-email-' . $MD5;
> 
>     return $Self->{MainObject}->FileWrite(
>         Location   => $Location,
>         Content    => \$Content,
>         Mode       => 'binmode',
>         Type       => 'Local',
>         Permission => '644',
>     );
> }
> 
> 1;
> 
> 
> 
> <<<<<<<<end IMAP.pm>>>>>>>>>>>>>>>
> 
> 
> 
> Jeremy Adams
> PC Support Specialist I
> Cedar Valley College
> 972.860.8086
> 
> 
> 
> 
> 
> ----------------------------------------------------------
> ----------- OTRS mailing list: otrs - Webpage:
> http://otrs.org/ Archive:
> http://lists.otrs.org/pipermail/otrs To unsubscribe:
> http://lists.otrs.org/cgi-bin/listinfo/otrs
> 
> NEW! ENTERPRISE SUBSCRIPTION - Get more information NOW!
> http://www.otrs.com/en/support/enterprise-subscription/




Francesco Simonini

Consultant
S.E.S.A. S.p.A.
Software E Sistemi Avanzati

20131 Milano Italy 
Via Teodosio, 65
Tel.      +39 02 4547 6444
Fax.      +39 02 4547 6475
Mobile: +39 348 7411960

E-mail:  [email protected]
Web:    http://www.sesaspa.it

-------------------------------------------------------------------------------
This message is for the designated recipient only and may
contain privileged or confidential information.

If you have received it in error, please notify the sender
immediately and delete the original.
Any other use of the email is prohibited.

-------------------------------------------------------------------------------


---------------------------------------------------------------------
OTRS mailing list: otrs - Webpage: http://otrs.org/
Archive: http://lists.otrs.org/pipermail/otrs
To unsubscribe: http://lists.otrs.org/cgi-bin/listinfo/otrs

NEW! ENTERPRISE SUBSCRIPTION - Get more information NOW!
http://www.otrs.com/en/support/enterprise-subscription/

Reply via email to