Project

General

Profile

Defect #9032 » 8979_project_leader_user_activation_V1.2.1.diff

Jérôme BATAILLE, 2011-08-10 17:20

View differences:

imap.rb (copie de travail)
29 29
        imap = Net::IMAP.new(host, port, ssl)        
30 30
        imap.login(imap_options[:username], imap_options[:password]) unless imap_options[:username].nil?
31 31
        imap.select(folder)
32

  
33
        # Get the unread messages
32 34
        imap.search(['NOT', 'SEEN']).each do |message_id|
35
          # Get the message body
33 36
          msg = imap.fetch(message_id,'RFC822')[0].attr['RFC822']
34 37
          logger.debug "Receiving message #{message_id}" if logger && logger.debug?
38

  
39
          # Redmine manages the message
35 40
          if MailHandler.receive(msg, options)
36
            logger.debug "Message #{message_id} successfully received" if logger && logger.debug?
41
            # Ennder trace the message enveloppe (to, cc, etc.)
42
            if logger && logger.debug?
43
              _enveloppe = imap.fetch(message_id, "ENVELOPE")[0].attr["ENVELOPE"]
44
              logger.debug "Message #{message_id} successfully received, to.emails=[#{ trace_to(_enveloppe) }]"
45
            fi
46

  
37 47
            if imap_options[:move_on_success]
38
              imap.copy(message_id, imap_options[:move_on_success])
48
              # Ennder new trace
49
              logger.debug "move to Archive" if logger && logger.debug?
50
              # Ennder Defect #9030 manage exception if the Imap Archive folder does not exist
51
              begin
52
                imap.copy(message_id, imap_options[:move_on_success])
53
              rescue
54
                logger.error "Exception : #{$!} (#{imap_options[:move_on_success]}), the folder does NOT exist (at the same level as INBOX)" if logger
55
              end
39 56
            end
57

  
58
            # Ennder new trace
59
            logger.debug "store Seen, Deleted..." if logger && logger.debug?
40 60
            imap.store(message_id, "+FLAGS", [:Seen, :Deleted])
41 61
          else
42
            logger.debug "Message #{message_id} can not be processed" if logger && logger.debug?
62
            logger.error "Message #{message_id} can not be processed" if logger
63

  
64
            # Ennder new trace
65
            logger.debug "store Seen..." if logger && logger.debug?
43 66
            imap.store(message_id, "+FLAGS", [:Seen])
67

  
44 68
            if imap_options[:move_on_failure]
45
              imap.copy(message_id, imap_options[:move_on_failure])
69
              #Ennder new trace
70
              logger.debug "copy..." if logger && logger.debug?
71

  
72
              # Ennder Defect #9030 manage exception if the Imap Archive folder does not exist
73
              begin
74
                imap.copy(message_id, imap_options[:move_on_failure])
75
              rescue
76
                logger.error "Exception : #{$!} (#{imap_options[:move_on_failure]}), the folder does NOT exist (at the same level as INBOX)" if logger
77
              end
78

  
79
              # Ennder new trace
80
              logger.debug "store Deleted..." if logger && logger.debug?
46 81
              imap.store(message_id, "+FLAGS", [:Deleted])
47 82
            end
48 83
          end
......
55 90
      def logger
56 91
        RAILS_DEFAULT_LOGGER
57 92
      end
93

  
94
      #Ennder
95
      def trace_to(p_enveloppe)
96
        _to_mails = ''
97

  
98
        p_enveloppe.to.each do |_to|
99
          _to_mails += _to.mailbox + '@' + _to.host + ','
100
        end
101

  
102
        _to_mails
103
      end
58 104
    end
59 105
  end
60 106
end
    (1-1/1)