Exemple #1
0
        internal void CreateInvite()
        {
            var addressBook = Session.GetSelectNamesDialog();
            addressBook.ForceResolution = true;
            addressBook.AllowMultipleSelection = true;
            addressBook.Caption = Resources.screentip_invite;
            if (!addressBook.Display()) return;
            var recips = addressBook.Recipients;
            var invalid = 0;
            var registered = 0;
            //collect the email addresses
            var selections = new Dictionary<string, Recipient>();
            foreach (Recipient recip in recips)
            {
                switch (recip.DisplayType)
                {
                    case OlDisplayType.olUser:
                        if (!EvalRecip(recip, ref selections)) invalid++;
                        break;
                    case OlDisplayType.olDistList:
                    case OlDisplayType.olPrivateDistList:
                        //case Outlook.OlDisplayType.olAgent: //might be query-dl
                        //expand the DL and evaluate each address
                        invalid += ExpandDl(recip, ref selections);
                        break;
                    default:
                        invalid++;
                        break;
                }
            }
            //if there's more than one account we need the active account

            //get comma-delimited list from dictionary
            var addresses = string.Join(",", selections.Keys);
            //pop up wait dialog
            var waitForm = new WaitForm
                               {
                                   Account = ActiveAccount,
                                   Configuration = ActiveAccount.Configurations[0],
                                   Recips = addresses,
                                   CheckRegistration = true
                               };
            if (waitForm.ShowDialog() != DialogResult.OK) return;
            var result = waitForm.RegistrationResponse;
            //strip out the registered users
            var regList = new List<string>();
            if (!string.IsNullOrEmpty(result))
            {
                var responses = result.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                var keys = addresses.Split(new[] { ',' });
                for (var i = 0; i < responses.Length; i++)
                {
                    if (!Convert.ToBoolean(responses[i])) continue;
                    var key = keys[i];
                    regList.Add(selections[key].Name);
                    selections.Remove(key);
                    registered++;
                }
            }
            Logger.Info("CreateInvite", string.Format(
                "user made {0} selections, {1} were invalid or duplicates and {2} were already registered",
                recips.Count, invalid, registered));
            if (regList.Count > 0)
            {
                if (selections.Count > 0)
                {
                    MessageBox.Show(string.Format(
                        Resources.invite_registered_alert + string.Join("{0}{1}", regList),
                        Environment.NewLine, "\t"),
                        Resources.invite_alert_caption,
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Information);
                }
                else
                {
                    MessageBox.Show(
                        Resources.invite_all_registered,
                        Resources.invite_alert_caption,
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Exclamation);
                }
            }
            if (selections.Count == 0) return;
            MailItem mail = Application.CreateItem(OlItemType.olMailItem);
            var mailRecips = mail.Recipients;
            foreach (Recipient selection in selections.Values)
            {
                var recip = mailRecips.Add(selection.Address);
                recip.Type = selection.Type;
                recip.Resolve();
            }
            mail.Subject = Resources.invite_subject;
            mail.Body = string.Format(Resources.invite_text,
                Environment.NewLine,
                Session.CurrentUser.Name);
            mail.Display();
        }
Exemple #2
0
 private void BtnEditClick(object sender, EventArgs e)
 {
     const string SOURCE = CLASS_NAME + "Edit_Click";
     Cursor = Cursors.WaitCursor;
     try
     {
         //grab the current content
         var content = winFormHtmlEditor1.BodyHtml;
         var updated = false;
         //has message changed?
         if (content != Content)
         {
             //revert any embedded image links back to pointers
             Utils.CollapseImgLinks(ref content);
             var encodedContent = ContentHandler.EncodeContent(
                 content, EncryptKey, EncryptKey2);
             string error;
             ContentHandler.UpdateContent(_account.SMTPAddress,
                 _configuration, encodedContent, Pointers[0], out error);
             if (!error.Equals("success"))
             {
                 MessageBox.Show(string.Format(
                     Resources.error_updating_content,
                     Environment.NewLine, error),
                     Resources.product_name,
                     MessageBoxButtons.OK,
                     MessageBoxIcon.Error);
                 return;
             }
             //save the change
             Content = content;
             updated = true;
         }
         //handle attachment updates - use WaitForm
         var updateList = new List<Attachment>();
         for (var i = 1; i < Pointers.Length; i++)
         {
             var pointer = Pointers[i];
             //is there a file copy?
             string path = Utils.GetFilePath(
                 _recordKey, AttachList[pointer].Index, AttachList[pointer].Name); //GetFile(pointer);
             if (File.Exists(path))
             {
                 //get the content
                 byte[] buf = File.ReadAllBytes(path);
                 //has it changed?
                 string hash = Cryptography.GetHash(buf);
                 if (hash != AttachList[pointer].Hash)
                 {
                     var attach = new Attachment
                                      {
                                          Name = Path.GetFileName(path),
                                          Pointer = pointer,
                                          Content = buf,
                                          Hash = hash,
                                          Type = (pointer == "0" ? 0 : 1)
                                      };
                     updateList.Add(attach);
                 }
             }
         }
         if (updateList.Count > 0)
         {
             var form = new WaitForm
                            {
                                Attachments = updateList,
                                Account = _account,
                                Configuration = _configuration,
                                EncryptKey = EncryptKey,
                                EncryptKey2 = EncryptKey2
                            };
             if (form.ShowDialog(this) == DialogResult.OK)
             {
                 updated = true;
                 //update the stored hash values
                 foreach (var attach in updateList)
                 {
                     AttachList[attach.Pointer].Hash = attach.Hash;
                 }
             }
             else updated = false;
         }
         if (updated)
         {
             MessageBox.Show(Resources.content_updated, Resources.product_name,
                 MessageBoxButtons.OK, MessageBoxIcon.Information);
             //relay this change to any Inspector windows for this object
             ThisAddIn.RelayContentChange(this, RecordKey, Content);
             if (!string.IsNullOrEmpty(_currentFilePath))
             {
                 //refetch the current attachment
                 previewHandlerControl.Open(_currentFilePath);
             }
         }
     }
     catch (Exception ex)
     {
         Logger.Error(SOURCE, ex.ToString());
     }
     finally
     {
         Cursor = Cursors.Default;
     }
 }
Exemple #3
0
        private void SaveFile(string pointer)
        {
            const string SOURCE = CLASS_NAME + "SaveFile";
            try
            {
                if (string.IsNullOrEmpty(pointer))
                {
                    Logger.Warning(SOURCE, "pointer is blank");
                    return;
                }
                //get the current path
                //string path = GetFile(pointer);
                string path;
                string hash;
                var waitForm = new WaitForm
                {
                    Pointer = pointer,
                    AttachList = AttachList,
                    RecordKey = _recordKey,
                    CurrentAccount = _account,
                    CurrentConfiguration = _configuration,
                    SenderAddress = _senderAddress,
                    ServerName = ServerName,
                    ServerPort = ServerPort,
                    EncryptKey = EncryptKey,
                    EncryptKey2 = EncryptKey2,
                    UserAgent = UserAgent,
                    CallType = DownloadUpload.Download
                };

                waitForm.ShowDialog();
                path = WaitForm.Path;
                hash = WaitForm.Hash;
                if (string.IsNullOrEmpty(path))
                {
                    return;
                }
                AttachList[pointer].Hash = hash;
                //raise Save Dialog
                saveFileDialog.FileName = Path.GetFileName(path);
                saveFileDialog.ShowDialog(this);
                string newPath = saveFileDialog.FileName;
                if (!string.IsNullOrEmpty(newPath))
                {
                    //copy the file to the new location
                    File.Copy(path, newPath);
                }
            }
            catch (Exception ex)
            {
                Logger.Error(SOURCE, ex.ToString());
            }
        }
Exemple #4
0
        private void SelectAttachment(object sender, EventArgs e)
        {
            var btn = (AttachPanel)sender;
            //clear all other button backgrounds
            btnMessage.Selected = false;
            ResetButtons(btn.Pointer);
            if (ThisAddIn.NoPreviewer) return;
            try
            {
                if (!string.IsNullOrEmpty(_duration) && _duration != "0") return;
                Cursor = Cursors.WaitCursor;
                var pointer = btn.Pointer;
                var embedded = pointer.StartsWith("embedded:");
                if (embedded)
                {
                    //state = btn.Pointer;
                    //get the embedded attachment
                    Redemption.Attachment attach = _embedded[btn.Pointer];
                    var message = attach.EmbeddedMsg;
                    if (message != null)
                    {
                        LoadAttachmentHeader("", "", attach.DisplayName, Utils.FormatFileSize(attach.Size));
                        //hide the htmlEditor row
                        winFormHtmlEditor1.Visible = false;
                        tableLayoutPanelMain.RowStyles[4].Height = 0;
                        tableLayoutPanelMain.RowStyles[5].Height = 0;
                        previewHandlerControl.Visible = false;
                        embeddedMsg1.LoadMsg(message, _recordKey,
                                             btn.Pointer.Replace("embedded:", ""),
                                             _entryId, _account, _senderAddress);
                        embeddedMsg1.Visible = true;
                    }
                }
                else
                {
                    ShowPreview(true);
                    //do we already have the attachment?
                    if (btn.Selected == false)
                    {
                        var waitForm = new WaitForm
                                       {
                                           Pointer = pointer,
                                           AttachList = AttachList,
                                           RecordKey = _recordKey,
                                           CurrentAccount = _account,
                                           CurrentConfiguration = _configuration,
                                           SenderAddress = _senderAddress,
                                           ServerName = ServerName,
                                           ServerPort = ServerPort,
                                           EncryptKey = EncryptKey,
                                           EncryptKey2 = EncryptKey2,
                                           UserAgent = UserAgent,
                                           CallType = DownloadUpload.Download
                                       };

                        waitForm.ShowDialog();
                    }

                    _currentFilePath = WaitForm.Path;
                    AttachList[pointer].Hash = WaitForm.Hash;
                    LoadAttachmentHeader(pointer, _currentFilePath, "", "");
                    if (File.Exists(_currentFilePath))
                    {
                        previewHandlerControl.Open(_currentFilePath);
                        //state = path;
                    }
                }

                btn.Selected = true;
            }
            finally
            {
                Cursor = Cursors.Default;
            }
            //if (string.IsNullOrEmpty(_duration)) return;
            //if(string.IsNullOrEmpty(state)) return;
            //if (_senderAddress != _account.SMTPAddress)
            //{
            //    if (embedded)
            //    {
            //        _embedded[btn.Pointer] = null;
            //    }
            //    else
            //    {
            //        string error;
            //        ContentHandler.RemoveRecipient(_account.SMTPAddress, _configuration,
            //                _senderAddress, btn.Pointer, ServerName, ServerPort, out error);
            //    }
            //}
            //_selfDestructTimer.Change(0, Timeout.Infinite);
            //_selfDestructTimer = new Timer(SelfDestructTimerTick,
            //    state,
            //    Convert.ToInt32(_duration)*1000,
            //    Timeout.Infinite);
        }
Exemple #5
0
        private bool PostAttachments(Account account, EcsConfiguration configuration,
            string encryptKey, string recips, ref List<string> pointers)
        {
            var source = CLASS_NAME + "PostAttachments";
            try
            {
                //get the bytes for the placeholder text
                var placeholder = Encoding.UTF8.GetBytes(Resources.placeholder_text);
                SafeMailItem safMail;
                try
                {
                    safMail = RedemptionLoader.new_SafeMailItem();
                }
                catch (Exception ex)
                {
                    Logger.Error("", String.Format(
                        "unable to work with attachments for {0}, failed to instantiate SafeMailItem: {1}",
                        MailItem.Subject, ex.Message));
                    return false;
                }
                //need to save the item first before we can work with the SafeMailItem
                MailItem.Save();
                safMail.Item = MailItem;
                var colAttach = safMail.Attachments;
                /* Outlook will move any embedded images to the head of the attachments table
                * if that's the case then we need to remove and re-add the other attachments
                * so that the pointer list will match the finished order
                */
                var hidden = false;
                string contentId;
                var savedAttach = new Dictionary<int, byte[]>();
                //do we have any embedded images?
                foreach (Redemption.Attachment rdoAttach in colAttach)
                {
                    Utils.GetAttachProps(rdoAttach, out contentId, out hidden);
                    if (hidden) break;
                }
                if (hidden)
                {
                    //walk through in reverse order
                    //delete and reattach each non-hidden attachment
                    for (var i = colAttach.Count; i > 0; i--)
                    {
                        Redemption.Attachment rdoAttach = colAttach[i];
                        Utils.GetAttachProps(rdoAttach, out contentId, out hidden);
                        if (hidden) continue;
                        if (rdoAttach.Type.Equals(5)) //embedded
                        {
                            var msg = rdoAttach.EmbeddedMsg;
                            rdoAttach.Delete();
                            colAttach.Add(msg, 5);
                        }
                        else
                        {
                            var path = Path.Combine(Path.GetTempPath(), "ChiaraMail", rdoAttach.FileName);
                            var displayName = rdoAttach.DisplayName;
                            if (File.Exists(path)) File.Delete(path);
                            rdoAttach.SaveAsFile(path);
                            rdoAttach.Delete();
                            rdoAttach = colAttach.Add(path, 1, Type.Missing, displayName);
                            //get the bytes and drop those in the dictionary, linked to the current index
                            savedAttach.Add(rdoAttach.Index, File.ReadAllBytes(path));
                            File.Delete(path);
                        }
                    }
                }

                //now loop through and collect the content (except for embedded messages)
                var attachList = new List<Attachment>();
                bool showForm = false;
                foreach (Redemption.Attachment rdoAttach in colAttach)
                {
                    var attach = new Attachment { Type = rdoAttach.Type };
                    switch (rdoAttach.Type)
                    {
                        case (int)OlAttachmentType.olEmbeddeditem:
                            //is this an ECS attachment?
                            var msg = rdoAttach.EmbeddedMsg;
                            if (Utils.HasChiaraHeader(msg))
                            {
                                ForwardEmbeddedECS(msg, recips, account);
                            }
                            //always add
                            attachList.Add(attach);
                            break;
                        case (int)OlAttachmentType.olByReference:
                        case (int)OlAttachmentType.olOLE:
                            attachList.Add(attach);
                            break;
                        case (int)OlAttachmentType.olByValue:
                            showForm = true;
                            //we may have already gotten the bytes
                            if (savedAttach.Count > 0 && savedAttach.ContainsKey(rdoAttach.Index))
                            {
                                attach.Content = savedAttach[rdoAttach.Index];
                            }
                            if (attach.Content == null || attach.Content.Length == 0)
                            {
                                //try just read the bytes from the binary property
                                //this could fail if the attachment is too big
                                try
                                {
                                    attach.Content = rdoAttach.AsArray != null
                                        ? rdoAttach.AsArray as byte[]
                                        : null;//.Fields[ThisAddIn.PR_ATTACH_DATA_BIN]);
                                }
                                catch
                                {
                                    attach.Content = null;
                                }
                            }
                            if (attach.Content == null)
                            {
                                //save to disk then get the bytes
                                var path = Path.Combine(Path.GetTempPath(), "ChiaraMail", rdoAttach.FileName);
                                if (File.Exists(path)) File.Delete(path);
                                rdoAttach.SaveAsFile(path);
                                attach.Content = File.ReadAllBytes(path);
                                File.Delete(path);
                            }
                            if (attach.Content != null)
                            {
                                attach.Index = rdoAttach.Index;
                                attach.Name = rdoAttach.DisplayName;
                                attachList.Add(attach);
                            }
                            else
                            {
                                Logger.Warning(source,
                                               "aborting: failed to retrieve content for " + rdoAttach.DisplayName);
                                MessageBox.Show(String.Format(
                                    "Unable to retrieve original content from {0}",
                                    rdoAttach.DisplayName), Resources.product_name,
                                                MessageBoxButtons.OK,
                                                MessageBoxIcon.Error);
                                return false;
                            }
                            break;
                    }
                }
                if (!showForm)
                {
                    pointers.AddRange(attachList.Select(attach => attach.Pointer));
                    return true;
                }
                //use the WaitForm to upload the attachments
                var win = new OutlookWin32Window(Inspector, Inspector.IsWordMail());
                var form = new WaitForm
                               {
                                   Attachments = attachList,
                                   Account = account,
                                   Configuration = configuration,
                                   Recips = recips,
                                   EncryptKey2 = encryptKey
                               };
                //use encryptKey2 for new post
                if (form.ShowDialog(win) == DialogResult.OK)
                {
                    //post succeeded for all attachments
                    //get the pointers
                    pointers.AddRange(form.Attachments.Select(attach => attach.Pointer));
                    //don't replace attachment bytes if we are sending content
                    if (NoPlaceholder) return true;
                    //loop back through to replace the original content with the placeholder bytes
                    foreach (Redemption.Attachment rdoAttach in colAttach)
                    {
                        if (rdoAttach.Type.Equals(1)) //OlAttachmentType.olByValue)
                        {
                            rdoAttach.Fields[ThisAddIn.PR_ATTACH_DATA_BIN] = placeholder;
                        }
                    }
                    return true;
                }
                //get the pointer list anyway so we can delete the items that got posted
                pointers.AddRange(form.Attachments
                                      .TakeWhile(attach => !String.IsNullOrEmpty(attach.Pointer))
                                      .Select(attach => attach.Pointer));
            }
            catch (Exception ex)
            {
                Logger.Error(source, ex.ToString());
            }
            return false;
        }