Subversion Repositories SmartDukaan

Rev

Rev 3369 | Rev 3390 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3369 Rev 3373
Line 40... Line 40...
40
    private static final String MAILOR_DAEMON_EMAIL_ID = "mailer-daemon@googlemail.com";
40
    private static final String MAILOR_DAEMON_EMAIL_ID = "mailer-daemon@googlemail.com";
41
    private static final Log log                   = LogFactory
41
    private static final Log log                   = LogFactory
42
                                                           .getLog(CRMEmailProcessor.class);
42
                                                           .getLog(CRMEmailProcessor.class);
43
    private Client           client;
43
    private Client           client;
44
 
44
 
45
    public CRMEmailProcessor() {
-
 
46
        try {
-
 
47
            client = new CRMClient().getClient();
-
 
48
        } catch (TTransportException e) {
-
 
49
            log.error("Could not create client", e);
-
 
50
        }
-
 
51
    }
-
 
52
 
-
 
53
    public void processEmail(Message message) throws MessagingException,
45
    public void processEmail(Message message) throws MessagingException,
54
            IOException, TException, UserContextException {
46
            IOException, TException, UserContextException {
55
        // Ignoring mails from Mailor daemon
47
        // Ignoring mails from Mailor daemon
56
        if (MAILOR_DAEMON_EMAIL_ID.equals(parseEmailId(message.getFrom()[0].toString()))) {
48
        if (MAILOR_DAEMON_EMAIL_ID.equals(parseEmailId(message.getFrom()[0].toString()))) {
57
            return;
49
            return;
Line 85... Line 77...
85
 
77
 
86
        return ticketId;
78
        return ticketId;
87
    }
79
    }
88
 
80
 
89
    public Date getLastProcessedTimestamp() throws ParseException, TException {
81
    public Date getLastProcessedTimestamp() throws ParseException, TException {
-
 
82
        client = new CRMClient().getClient();
90
        return new Date(client.getLastEmailProcessedTimestamp());
83
        return new Date(client.getLastEmailProcessedTimestamp());
91
    }
84
    }
92
 
85
 
93
    public void updateLastProcessedTimestamp(Date date) throws TException {
86
    public void updateLastProcessedTimestamp(Date date) throws TException {
94
        client = new CRMClient().getClient();
87
        client = new CRMClient().getClient();
95
        client.updateLastEmailProcessedTimestamp(date.getTime());
88
        client.updateLastEmailProcessedTimestamp(date.getTime());
96
    }
89
    }
97
 
90
 
98
    private void updateTicket(Long ticketId, Message message) {
91
    private void updateTicket(Long ticketId, Message message) {
99
        try {
92
        try {
-
 
93
            client = new CRMClient().getClient();
100
            Ticket ticket = client.getTicket(ticketId);
94
            Ticket ticket = client.getTicket(ticketId);
101
            Activity activity = new Activity();
95
            Activity activity = new Activity();
102
            activity.setTicketId(ticketId);
96
            activity.setTicketId(ticketId);
103
            activity.setTicketAssigneeId(ticket.getAssigneeId());
97
            activity.setTicketAssigneeId(ticket.getAssigneeId());
104
            activity.setTicketCategory(ticket.getCategory());
98
            activity.setTicketCategory(ticket.getCategory());
Line 116... Line 110...
116
 
110
 
117
            if (TicketStatus.CLOSED.equals(ticket.getStatus())) {
111
            if (TicketStatus.CLOSED.equals(ticket.getStatus())) {
118
                ticket.setStatus(TicketStatus.REOPEN);
112
                ticket.setStatus(TicketStatus.REOPEN);
119
            }
113
            }
120
 
114
 
-
 
115
            client = new CRMClient().getClient();
121
            client.updateTicket(ticket, activity);
116
            client.updateTicket(ticket, activity);
122
        } catch (TTransportException e) {
117
        } catch (TTransportException e) {
123
            log.error("Could not update ticket " + ticketId + " with mail "
118
            log.error("Could not update ticket " + ticketId + " with mail "
124
                    + message, e);
119
                    + message, e);
125
        } catch (TException e) {
120
        } catch (TException e) {
Line 164... Line 159...
164
        activity.setTicketPriority(ticket.getPriority());
159
        activity.setTicketPriority(ticket.getPriority());
165
        activity.setTicketStatus(ticket.getStatus());
160
        activity.setTicketStatus(ticket.getStatus());
166
        activity.setType(ActivityType.RECEIVED_EMAIL_FROM_CUSTOMER);
161
        activity.setType(ActivityType.RECEIVED_EMAIL_FROM_CUSTOMER);
167
        activity.setCreatorId(CRMConstants.ADMIN_AGENT_ID);
162
        activity.setCreatorId(CRMConstants.ADMIN_AGENT_ID);
168
 
163
 
-
 
164
        client = new CRMClient().getClient();
169
        client.insertTicket(ticket, activity);
165
        client.insertTicket(ticket, activity);
170
    }
166
    }
171
 
167
 
172
    // parsing email Id from strings like
168
    // parsing email Id from strings like
173
    // "Pankaj Jain <ponkoj@hotmail.com>"
169
    // "Pankaj Jain <ponkoj@hotmail.com>"
Line 182... Line 178...
182
    }
178
    }
183
 
179
 
184
    private String convertMessageToText(Message message)
180
    private String convertMessageToText(Message message)
185
            throws MessagingException, IOException {
181
            throws MessagingException, IOException {
186
        String messageContent = getText(message);
182
        String messageContent = getText(message);
187
        System.out.println(messageContent);
-
 
188
 
183
 
189
        String content = "From: " + message.getFrom()[0].toString()
184
        String content = "From: " + message.getFrom()[0].toString()
190
                + "\n\nSubject: " + message.getSubject() + "\n\nBody: "
185
                + "\n\nSubject: " + message.getSubject() + "\n\nBody: "
191
                + messageContent;
186
                + messageContent;
192
 
187