0

I have been working on an IMAP client to get emails from Gmail. My application worked fine until about an hour ago, when attachments stopped being retrieved.

The connection and messaging is being handled by imapX.

Connection is OKAY Login is OKAY Getting folders is OKAY Getting messages is OKAY

At this point attachments.Count == 0. It was working earlier this afternoon so I wonder if I have been over testing and Google have blacklisted my computer for a while? Does anyone know if this is the case? - Been running perhaps once every 5-10 minutes, maybe more at times so this could be a plausible issue.

I have attempted to send a new email with a totally new file and it still does not see the attachment (but it is (always) seeing the messages themselves).

Can any anyone shine some light on this issue?

EDIT : Header includes the following tag {[X-MS-Has-Attach, yes]}

EDIT (code) :

private void PollMailFolders(object state)
    {
        try
        {

            if(_imapClient == null || !_imapClient.IsConnected)
                _imapClient = new ImapClient(_config.Server, _config.Port, true);

            if (_imapClient.Connection())
            {
                if(!_imapClient.IsLogined)
                    _imapClient.LogIn(_config.Username, _config.Password);

                string dateSearch = string.Format(
                    "SINCE {0:d-MMM-yyyy}{1}", DateTime.Today.AddDays(-_config.HistoryOnStartupDays),
                                                  _isFirstTime ? "" : " UNSEEN");

                _isFirstTime = false;

                foreach (Folder folder in _imapClient.Folders["SSForecasts"].SubFolder)
                {
                    var messages = _imapClient.Folders[folder.Name].Search(dateSearch, false);

                    foreach (Message m in messages)
                    {
                        m.Process();

                        foreach (var a in m.Attachments)
                        {
                            SendDataToParser(_encoding.GetString(a.FileData), folder.Name);
                        }
                        m.SetFlag(ImapFlags.SEEN);
                    }
                }
            }
        }
        catch(Exception e)
        {
            _diagnostics.Logger.ErrorFormat("Error in PollMailFolders: {0}", e);
        }
    }
Matt Canty
  • 2,395
  • 5
  • 35
  • 50
  • Code will be required to help you. – Security Hound Feb 14 '12 at 18:07
  • Okay, will post tomorrow - not at work now. As there is no difference between the working and not working code (90% sure!!! - don't need to tell me about spelling errors etc etc) I figured the problem must be something to do with limits on Gmail Imap activity. – Matt Canty Feb 14 '12 at 18:21
  • purely speculative; but it could also be an over-zealous firewall. – SimonMayer Feb 14 '12 at 18:59

1 Answers1

0

I have produced a work around which allows me to get the attachment data. Not the solution I had in mind, though it does work.

Simple filename extension check followed by a conversion of the message data.

BTW: _encoding = Encoding.GetEncoding(1252);

            if (bodyPart.ContentFilename.EndsWith(".csv"))
            {
                return _encoding.GetString(Convert.FromBase64String(bodyPart.ContentStream));
            }
Matt Canty
  • 2,395
  • 5
  • 35
  • 50