summaryrefslogtreecommitdiffstats
path: root/comm/mailnews/base/src/nsMsgMailNewsUrl.cpp
blob: 3796aeaef25e2818161f34a515a44fdaf5098900 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "msgCore.h"
#include "nsMsgMailNewsUrl.h"
#include "nsIMsgAccountManager.h"
#include "nsString.h"
#include "nsILoadGroup.h"
#include "nsIDocShell.h"
#include "nsIWebProgress.h"
#include "nsIWebProgressListener.h"
#include "nsIInterfaceRequestor.h"
#include "nsIInterfaceRequestorUtils.h"
#include "nsIIOService.h"
#include "nsNetCID.h"
#include "nsIStreamListener.h"
#include "nsIOutputStream.h"
#include "nsIInputStream.h"
#include "nsNetUtil.h"
#include "nsIFile.h"
#include "prmem.h"
#include <time.h>
#include "nsMsgUtils.h"
#include "mozilla/Components.h"
#include "nsProxyRelease.h"
#include "mozilla/Encoding.h"
#include "nsDocShellLoadState.h"
#include "nsContentUtils.h"
#include "nsIObjectInputStream.h"
#include "nsIObjectOutputStream.h"
#include "nsIChannel.h"

nsMsgMailNewsUrl::nsMsgMailNewsUrl() {
  // nsIURI specific state
  m_runningUrl = false;
  m_updatingFolder = false;
  m_msgIsInLocalCache = false;
  m_suppressErrorMsgs = false;
  m_hasNormalizedOrigin = false;  // SetSpecInternal() will set this correctly.
  mMaxProgress = -1;
}

#define NOTIFY_URL_LISTENERS(propertyfunc_, params_)                \
  PR_BEGIN_MACRO                                                    \
  nsTObserverArray<nsCOMPtr<nsIUrlListener>>::ForwardIterator iter( \
      mUrlListeners);                                               \
  while (iter.HasMore()) {                                          \
    nsCOMPtr<nsIUrlListener> listener = iter.GetNext();             \
    listener->propertyfunc_ params_;                                \
  }                                                                 \
  PR_END_MACRO

nsMsgMailNewsUrl::~nsMsgMailNewsUrl() {
  // In IMAP this URL is created and destroyed on the imap thread,
  // so we must ensure that releases of XPCOM objects (which might be
  // implemented by non-threadsafe JS components) are released on the
  // main thread.
  NS_ReleaseOnMainThread("nsMsgMailNewsUrl::m_baseURL", m_baseURL.forget());
  NS_ReleaseOnMainThread("nsMsgMailNewsUrl::mMimeHeaders",
                         mMimeHeaders.forget());
  NS_ReleaseOnMainThread("nsMsgMailNewsUrl::m_searchSession",
                         m_searchSession.forget());

  nsTObserverArray<nsCOMPtr<nsIUrlListener>>::ForwardIterator iter(
      mUrlListeners);
  while (iter.HasMore()) {
    nsCOMPtr<nsIUrlListener> listener = iter.GetNext();
    if (listener)
      NS_ReleaseOnMainThread("nsMsgMailNewsUrl::mUrlListeners",
                             listener.forget());
  }
}

NS_IMPL_ADDREF(nsMsgMailNewsUrl)
NS_IMPL_RELEASE(nsMsgMailNewsUrl)

// We want part URLs to QI to nsIURIWithSpecialOrigin so we can give
// them a "normalized" origin. URLs that already have a "normalized"
// origin should not QI to nsIURIWithSpecialOrigin.
NS_INTERFACE_MAP_BEGIN(nsMsgMailNewsUrl)
  NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIMsgMailNewsUrl)
  NS_INTERFACE_MAP_ENTRY(nsIMsgMailNewsUrl)
  NS_INTERFACE_MAP_ENTRY(nsIURL)
  NS_INTERFACE_MAP_ENTRY(nsIURI)
  NS_INTERFACE_MAP_ENTRY(nsISerializable)
  NS_INTERFACE_MAP_ENTRY(nsIClassInfo)
  NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsIURIWithSpecialOrigin,
                                     m_hasNormalizedOrigin)
NS_INTERFACE_MAP_END

//--------------------------
// Support for serialization
//--------------------------
// nsMsgMailNewsUrl is only partly serialized by serializing the "base URL"
// which is an nsStandardURL, or by only serializing the Spec. This may
// cause problems in the future. See bug 1512356 and bug 1515337 for details,
// follow-up in bug 1512698.

NS_IMETHODIMP_(void)
nsMsgMailNewsUrl::Serialize(mozilla::ipc::URIParams& aParams) {
  m_baseURL->Serialize(aParams);
}

//----------------------------
// Support for nsISerializable
//----------------------------
NS_IMETHODIMP nsMsgMailNewsUrl::Read(nsIObjectInputStream* stream) {
  nsAutoCString urlstr;
  nsresult rv = NS_ReadOptionalCString(stream, urlstr);
  NS_ENSURE_SUCCESS(rv, rv);
  nsCOMPtr<nsIIOService> ioService = mozilla::components::IO::Service();
  NS_ENSURE_TRUE(ioService, NS_ERROR_UNEXPECTED);
  nsCOMPtr<nsIURI> url;
  rv = ioService->NewURI(urlstr, nullptr, nullptr, getter_AddRefs(url));
  NS_ENSURE_SUCCESS(rv, rv);
  m_baseURL = do_QueryInterface(url);
  return NS_OK;
}

NS_IMETHODIMP nsMsgMailNewsUrl::Write(nsIObjectOutputStream* stream) {
  nsAutoCString urlstr;
  nsresult rv = m_baseURL->GetSpec(urlstr);
  NS_ENSURE_SUCCESS(rv, rv);
  return NS_WriteOptionalStringZ(stream, urlstr.get());
}

//-------------------------
// Support for nsIClassInfo
//-------------------------
NS_IMETHODIMP nsMsgMailNewsUrl::GetInterfaces(nsTArray<nsIID>& array) {
  array.Clear();
  return NS_OK;
}

NS_IMETHODIMP nsMsgMailNewsUrl::GetScriptableHelper(
    nsIXPCScriptable** _retval) {
  *_retval = nullptr;
  return NS_OK;
}

NS_IMETHODIMP nsMsgMailNewsUrl::GetContractID(nsACString& aContractID) {
  aContractID.SetIsVoid(true);
  return NS_OK;
}

NS_IMETHODIMP nsMsgMailNewsUrl::GetClassDescription(
    nsACString& aClassDescription) {
  aClassDescription.SetIsVoid(true);
  return NS_OK;
}

NS_IMETHODIMP nsMsgMailNewsUrl::GetClassID(nsCID** aClassID) {
  *aClassID = (nsCID*)moz_xmalloc(sizeof(nsCID));
  return GetClassIDNoAlloc(*aClassID);
}

NS_IMETHODIMP nsMsgMailNewsUrl::GetFlags(uint32_t* aFlags) {
  *aFlags = 0;
  return NS_OK;
}

#define NS_MSGMAILNEWSURL_CID                        \
  {                                                  \
    0x3fdae3ab, 0x4ac1, 0x4ad4, {                    \
      0xb2, 0x8a, 0x28, 0xd0, 0xfa, 0x36, 0x39, 0x29 \
    }                                                \
  }
static NS_DEFINE_CID(kNS_MSGMAILNEWSURL_CID, NS_MSGMAILNEWSURL_CID);
NS_IMETHODIMP nsMsgMailNewsUrl::GetClassIDNoAlloc(nsCID* aClassIDNoAlloc) {
  *aClassIDNoAlloc = kNS_MSGMAILNEWSURL_CID;
  return NS_OK;
}

//------------------------------------
// Support for nsIURIWithSpecialOrigin
//------------------------------------
NS_IMETHODIMP nsMsgMailNewsUrl::GetOrigin(nsIURI** aOrigin) {
  MOZ_ASSERT(m_hasNormalizedOrigin,
             "nsMsgMailNewsUrl::GetOrigin() can only be called for URLs with "
             "normalized spec");

  if (!m_normalizedOrigin) {
    nsCOMPtr<nsIMsgMessageUrl> msgUrl;
    QueryInterface(NS_GET_IID(nsIMsgMessageUrl), getter_AddRefs(msgUrl));

    nsAutoCString spec;
    if (!msgUrl || NS_FAILED(msgUrl->GetNormalizedSpec(spec))) {
      MOZ_ASSERT(false, "Can't get normalized spec");
      // just use the normal spec.
      GetSpec(spec);
    }

    nsresult rv = NS_NewURI(getter_AddRefs(m_normalizedOrigin), spec);
    NS_ENSURE_SUCCESS(rv, rv);
  }

  NS_IF_ADDREF(*aOrigin = m_normalizedOrigin);
  return NS_OK;
}

////////////////////////////////////////////////////////////////////////////////////
// Begin nsIMsgMailNewsUrl specific support
////////////////////////////////////////////////////////////////////////////////////

nsresult nsMsgMailNewsUrl::GetUrlState(bool* aRunningUrl) {
  if (aRunningUrl) *aRunningUrl = m_runningUrl;

  return NS_OK;
}

nsresult nsMsgMailNewsUrl::SetUrlState(bool aRunningUrl, nsresult aExitCode) {
  // if we already knew this running state, return, unless the url was aborted
  if (m_runningUrl == aRunningUrl && aExitCode != NS_MSG_ERROR_URL_ABORTED) {
    return NS_OK;
  }
  m_runningUrl = aRunningUrl;
  nsCOMPtr<nsIMsgStatusFeedback> statusFeedback;

  // put this back - we need it for urls that don't run through the doc loader
  if (NS_SUCCEEDED(GetStatusFeedback(getter_AddRefs(statusFeedback))) &&
      statusFeedback) {
    if (m_runningUrl)
      statusFeedback->StartMeteors();
    else {
      statusFeedback->ShowProgress(0);
      statusFeedback->StopMeteors();
    }
  }

  if (m_runningUrl) {
    NOTIFY_URL_LISTENERS(OnStartRunningUrl, (this));
  } else {
    NOTIFY_URL_LISTENERS(OnStopRunningUrl, (this, aExitCode));
    mUrlListeners.Clear();
  }

  return NS_OK;
}

NS_IMETHODIMP nsMsgMailNewsUrl::RegisterListener(nsIUrlListener* aUrlListener) {
  NS_ENSURE_ARG_POINTER(aUrlListener);
  mUrlListeners.AppendElement(aUrlListener);
  return NS_OK;
}

nsresult nsMsgMailNewsUrl::UnRegisterListener(nsIUrlListener* aUrlListener) {
  NS_ENSURE_ARG_POINTER(aUrlListener);

  // Due to the way mailnews is structured, some listeners attempt to remove
  // themselves twice. This may in fact be an error in the coding, however
  // if they didn't do it as they do currently, then they could fail to remove
  // their listeners.
  mUrlListeners.RemoveElement(aUrlListener);

  return NS_OK;
}

NS_IMETHODIMP nsMsgMailNewsUrl::GetServer(
    nsIMsgIncomingServer** aIncomingServer) {
  // mscott --> we could cache a copy of the server here....but if we did, we
  // run the risk of leaking the server if any single url gets leaked....of
  // course that shouldn't happen...but it could. so i'm going to look it up
  // every time and we can look at caching it later.

  nsresult rv;

  nsAutoCString urlstr;
  rv = m_baseURL->GetSpec(urlstr);
  NS_ENSURE_SUCCESS(rv, rv);

  nsCOMPtr<nsIURL> url;
  rv = NS_MutateURI(NS_STANDARDURLMUTATOR_CONTRACTID)
           .SetSpec(urlstr)
           .Finalize(url);
  NS_ENSURE_SUCCESS(rv, rv);

  nsAutoCString scheme;
  rv = GetScheme(scheme);
  if (NS_SUCCEEDED(rv)) {
    if (scheme.EqualsLiteral("pop")) scheme.AssignLiteral("pop3");
    // we use "nntp" in the server list so translate it here.
    if (scheme.EqualsLiteral("news")) scheme.AssignLiteral("nntp");
    rv = NS_MutateURI(url).SetScheme(scheme).Finalize(url);
    NS_ENSURE_SUCCESS(rv, rv);
    nsCOMPtr<nsIMsgAccountManager> accountManager =
        do_GetService("@mozilla.org/messenger/account-manager;1", &rv);
    NS_ENSURE_SUCCESS(rv, rv);

    nsCOMPtr<nsIMsgIncomingServer> server;
    rv = accountManager->FindServerByURI(url, aIncomingServer);
    if (!*aIncomingServer && scheme.EqualsLiteral("imap")) {
      // look for any imap server with this host name so clicking on
      // other users folder urls will work. We could override this method
      // for imap urls, or we could make caching of servers work and
      // just set the server in the imap code for this case.
      rv = NS_MutateURI(url).SetUserPass(EmptyCString()).Finalize(url);
      NS_ENSURE_SUCCESS(rv, rv);
      rv = accountManager->FindServerByURI(url, aIncomingServer);
    }
  }

  return rv;
}

NS_IMETHODIMP nsMsgMailNewsUrl::GetMsgWindow(nsIMsgWindow** aMsgWindow) {
  NS_ENSURE_ARG_POINTER(aMsgWindow);
  *aMsgWindow = nullptr;

  nsCOMPtr<nsIMsgWindow> msgWindow(do_QueryReferent(m_msgWindowWeak));
  msgWindow.forget(aMsgWindow);
  return *aMsgWindow ? NS_OK : NS_ERROR_NULL_POINTER;
}

NS_IMETHODIMP nsMsgMailNewsUrl::SetMsgWindow(nsIMsgWindow* aMsgWindow) {
#ifdef DEBUG_David_Bienvenu
  NS_ASSERTION(aMsgWindow || !m_msgWindowWeak,
               "someone crunching non-null msg window");
#endif
  m_msgWindowWeak = do_GetWeakReference(aMsgWindow);
  return NS_OK;
}

NS_IMETHODIMP nsMsgMailNewsUrl::GetStatusFeedback(
    nsIMsgStatusFeedback** aMsgFeedback) {
  // note: it is okay to return a null status feedback and not return an error
  // it's possible the url really doesn't have status feedback
  *aMsgFeedback = nullptr;
  if (!m_statusFeedbackWeak) {
    nsCOMPtr<nsIMsgWindow> msgWindow(do_QueryReferent(m_msgWindowWeak));
    if (msgWindow) msgWindow->GetStatusFeedback(aMsgFeedback);
  } else {
    nsCOMPtr<nsIMsgStatusFeedback> statusFeedback(
        do_QueryReferent(m_statusFeedbackWeak));
    statusFeedback.forget(aMsgFeedback);
  }
  return *aMsgFeedback ? NS_OK : NS_ERROR_NULL_POINTER;
}

NS_IMETHODIMP nsMsgMailNewsUrl::SetStatusFeedback(
    nsIMsgStatusFeedback* aMsgFeedback) {
  if (aMsgFeedback) m_statusFeedbackWeak = do_GetWeakReference(aMsgFeedback);
  return NS_OK;
}

NS_IMETHODIMP nsMsgMailNewsUrl::GetMaxProgress(int64_t* aMaxProgress) {
  *aMaxProgress = mMaxProgress;
  return NS_OK;
}

NS_IMETHODIMP nsMsgMailNewsUrl::SetMaxProgress(int64_t aMaxProgress) {
  mMaxProgress = aMaxProgress;
  return NS_OK;
}

NS_IMETHODIMP nsMsgMailNewsUrl::GetLoadGroup(nsILoadGroup** aLoadGroup) {
  *aLoadGroup = nullptr;
  // note: it is okay to return a null load group and not return an error
  // it's possible the url really doesn't have load group
  nsCOMPtr<nsILoadGroup> loadGroup(do_QueryReferent(m_loadGroupWeak));
  if (!loadGroup) {
    nsCOMPtr<nsIMsgWindow> msgWindow(do_QueryReferent(m_msgWindowWeak));
    if (msgWindow) {
      // XXXbz This is really weird... why are we getting some
      // random loadgroup we're not really a part of?
      nsCOMPtr<nsIDocShell> docShell;
      msgWindow->GetRootDocShell(getter_AddRefs(docShell));
      loadGroup = do_GetInterface(docShell);
      m_loadGroupWeak = do_GetWeakReference(loadGroup);
    }
  }
  loadGroup.forget(aLoadGroup);
  return *aLoadGroup ? NS_OK : NS_ERROR_NULL_POINTER;
}

NS_IMETHODIMP nsMsgMailNewsUrl::GetUpdatingFolder(bool* aResult) {
  NS_ENSURE_ARG(aResult);
  *aResult = m_updatingFolder;
  return NS_OK;
}

NS_IMETHODIMP nsMsgMailNewsUrl::SetUpdatingFolder(bool updatingFolder) {
  m_updatingFolder = updatingFolder;
  return NS_OK;
}

NS_IMETHODIMP nsMsgMailNewsUrl::GetMsgIsInLocalCache(bool* aMsgIsInLocalCache) {
  NS_ENSURE_ARG(aMsgIsInLocalCache);
  *aMsgIsInLocalCache = m_msgIsInLocalCache;
  return NS_OK;
}

NS_IMETHODIMP nsMsgMailNewsUrl::SetMsgIsInLocalCache(bool aMsgIsInLocalCache) {
  m_msgIsInLocalCache = aMsgIsInLocalCache;
  return NS_OK;
}

NS_IMETHODIMP nsMsgMailNewsUrl::GetSuppressErrorMsgs(bool* aSuppressErrorMsgs) {
  NS_ENSURE_ARG(aSuppressErrorMsgs);
  *aSuppressErrorMsgs = m_suppressErrorMsgs;
  return NS_OK;
}

NS_IMETHODIMP nsMsgMailNewsUrl::SetSuppressErrorMsgs(bool aSuppressErrorMsgs) {
  m_suppressErrorMsgs = aSuppressErrorMsgs;
  return NS_OK;
}

NS_IMETHODIMP nsMsgMailNewsUrl::GetErrorCode(nsACString& aErrorCode) {
  aErrorCode = m_errorCode;
  return NS_OK;
}

NS_IMETHODIMP nsMsgMailNewsUrl::SetErrorCode(const nsACString& aErrorCode) {
  m_errorCode.Assign(aErrorCode);
  return NS_OK;
}

NS_IMETHODIMP nsMsgMailNewsUrl::GetErrorMessage(nsAString& aErrorMessage) {
  aErrorMessage = m_errorMessage;
  return NS_OK;
}

NS_IMETHODIMP nsMsgMailNewsUrl::SetErrorMessage(
    const nsAString& aErrorMessage) {
  m_errorMessage.Assign(aErrorMessage);
  return NS_OK;
}

NS_IMETHODIMP nsMsgMailNewsUrl::SetSeeOtherURI(const nsACString& aSeeOtherURI) {
  m_seeOtherURI.Assign(aSeeOtherURI);
  return NS_OK;
}

NS_IMETHODIMP nsMsgMailNewsUrl::GetSeeOtherURI(nsACString& aSeeOtherURI) {
  aSeeOtherURI = m_seeOtherURI;
  return NS_OK;
}

NS_IMETHODIMP nsMsgMailNewsUrl::IsUrlType(uint32_t type, bool* isType) {
  // base class doesn't know about any specific types
  NS_ENSURE_ARG(isType);
  *isType = false;
  return NS_OK;
}

NS_IMETHODIMP nsMsgMailNewsUrl::SetSearchSession(
    nsIMsgSearchSession* aSearchSession) {
  if (aSearchSession) m_searchSession = aSearchSession;
  return NS_OK;
}

NS_IMETHODIMP nsMsgMailNewsUrl::GetSearchSession(
    nsIMsgSearchSession** aSearchSession) {
  NS_ENSURE_ARG(aSearchSession);
  NS_IF_ADDREF(*aSearchSession = m_searchSession);
  return NS_OK;
}

////////////////////////////////////////////////////////////////////////////////////
// End nsIMsgMailNewsUrl specific support
////////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////////
// Begin nsIURI support
////////////////////////////////////////////////////////////////////////////////////

NS_IMETHODIMP nsMsgMailNewsUrl::GetSpec(nsACString& aSpec) {
  return m_baseURL->GetSpec(aSpec);
}

nsresult nsMsgMailNewsUrl::CreateURL(const nsACString& aSpec, nsIURL** aURL) {
  nsCOMPtr<nsIURL> url;
  nsresult rv = NS_MutateURI(NS_STANDARDURLMUTATOR_CONTRACTID)
                    .SetSpec(aSpec)
                    .Finalize(url);
  NS_ENSURE_SUCCESS(rv, rv);
  url.forget(aURL);
  return NS_OK;
}

#define FILENAME_PART_LEN 10

nsresult nsMsgMailNewsUrl::SetSpecInternal(const nsACString& aSpec) {
  nsAutoCString spec(aSpec);
  // Parse out "filename" attribute if present.
  char *start, *end;
  start = PL_strcasestr(spec.BeginWriting(), "?filename=");
  if (!start) start = PL_strcasestr(spec.BeginWriting(), "&filename=");
  if (start) {  // Make sure we only get our own value.
    end = PL_strcasestr((char*)(start + FILENAME_PART_LEN), "&");
    if (end) {
      *end = 0;
      mAttachmentFileName = start + FILENAME_PART_LEN;
      *end = '&';
    } else
      mAttachmentFileName = start + FILENAME_PART_LEN;
  }

  // Now, set the rest.
  nsresult rv = CreateURL(aSpec, getter_AddRefs(m_baseURL));
  NS_ENSURE_SUCCESS(rv, rv);

  // Check whether the URL is in normalized form.
  nsCOMPtr<nsIMsgMessageUrl> msgUrl;
  QueryInterface(NS_GET_IID(nsIMsgMessageUrl), getter_AddRefs(msgUrl));

  nsAutoCString normalizedSpec;
  if (!msgUrl || NS_FAILED(msgUrl->GetNormalizedSpec(normalizedSpec))) {
    // If we can't get the normalized spec, never QI this to
    // nsIURIWithSpecialOrigin.
    m_hasNormalizedOrigin = false;
  } else {
    m_hasNormalizedOrigin = !spec.Equals(normalizedSpec);
  }
  return NS_OK;
}

NS_IMETHODIMP nsMsgMailNewsUrl::GetPrePath(nsACString& aPrePath) {
  return m_baseURL->GetPrePath(aPrePath);
}

NS_IMETHODIMP nsMsgMailNewsUrl::GetScheme(nsACString& aScheme) {
  return m_baseURL->GetScheme(aScheme);
}

nsresult nsMsgMailNewsUrl::SetScheme(const nsACString& aScheme) {
  return NS_MutateURI(m_baseURL).SetScheme(aScheme).Finalize(m_baseURL);
}

NS_IMETHODIMP nsMsgMailNewsUrl::GetUserPass(nsACString& aUserPass) {
  return m_baseURL->GetUserPass(aUserPass);
}

nsresult nsMsgMailNewsUrl::SetUserPass(const nsACString& aUserPass) {
  return NS_MutateURI(m_baseURL).SetUserPass(aUserPass).Finalize(m_baseURL);
}

NS_IMETHODIMP nsMsgMailNewsUrl::GetUsername(nsACString& aUsername) {
  /* note:  this will return an escaped string */
  return m_baseURL->GetUsername(aUsername);
}

nsresult nsMsgMailNewsUrl::SetUsername(const nsACString& aUsername) {
  return NS_MutateURI(m_baseURL).SetUsername(aUsername).Finalize(m_baseURL);
}

nsresult nsMsgMailNewsUrl::SetUsernameInternal(const nsACString& aUsername) {
  return NS_MutateURI(m_baseURL).SetUsername(aUsername).Finalize(m_baseURL);
}

NS_IMETHODIMP nsMsgMailNewsUrl::GetPassword(nsACString& aPassword) {
  return m_baseURL->GetPassword(aPassword);
}

nsresult nsMsgMailNewsUrl::SetPassword(const nsACString& aPassword) {
  return NS_MutateURI(m_baseURL).SetPassword(aPassword).Finalize(m_baseURL);
}

NS_IMETHODIMP nsMsgMailNewsUrl::GetHostPort(nsACString& aHostPort) {
  return m_baseURL->GetHostPort(aHostPort);
}

nsresult nsMsgMailNewsUrl::SetHostPort(const nsACString& aHostPort) {
  return NS_MutateURI(m_baseURL).SetHostPort(aHostPort).Finalize(m_baseURL);
}

NS_IMETHODIMP nsMsgMailNewsUrl::GetHost(nsACString& aHost) {
  return m_baseURL->GetHost(aHost);
}

nsresult nsMsgMailNewsUrl::SetHost(const nsACString& aHost) {
  return NS_MutateURI(m_baseURL).SetHost(aHost).Finalize(m_baseURL);
}

NS_IMETHODIMP nsMsgMailNewsUrl::GetPort(int32_t* aPort) {
  return m_baseURL->GetPort(aPort);
}

nsresult nsMsgMailNewsUrl::SetPort(int32_t aPort) {
  return NS_MutateURI(m_baseURL).SetPort(aPort).Finalize(m_baseURL);
}

nsresult nsMsgMailNewsUrl::SetPortInternal(int32_t aPort) {
  return NS_MutateURI(m_baseURL).SetPort(aPort).Finalize(m_baseURL);
}

NS_IMETHODIMP nsMsgMailNewsUrl::GetPathQueryRef(nsACString& aPath) {
  return m_baseURL->GetPathQueryRef(aPath);
}

nsresult nsMsgMailNewsUrl::SetPathQueryRef(const nsACString& aPath) {
  return NS_MutateURI(m_baseURL).SetPathQueryRef(aPath).Finalize(m_baseURL);
}

NS_IMETHODIMP nsMsgMailNewsUrl::GetAsciiHost(nsACString& aHostA) {
  return m_baseURL->GetAsciiHost(aHostA);
}

NS_IMETHODIMP nsMsgMailNewsUrl::GetAsciiHostPort(nsACString& aHostPortA) {
  return m_baseURL->GetAsciiHostPort(aHostPortA);
}

NS_IMETHODIMP nsMsgMailNewsUrl::GetAsciiSpec(nsACString& aSpecA) {
  return m_baseURL->GetAsciiSpec(aSpecA);
}

NS_IMETHODIMP nsMsgMailNewsUrl::GetBaseURI(nsIURI** aBaseURI) {
  NS_ENSURE_ARG_POINTER(aBaseURI);
  return m_baseURL->QueryInterface(NS_GET_IID(nsIURI), (void**)aBaseURI);
}

NS_IMETHODIMP nsMsgMailNewsUrl::Equals(nsIURI* other, bool* _retval) {
  // The passed-in URI might be a mail news url. Pass our inner URL to its
  // Equals method. The other mail news url will then pass its inner URL to
  // to the Equals method of our inner URL. Other URIs will return false.
  if (other) return other->Equals(m_baseURL, _retval);

  return m_baseURL->Equals(other, _retval);
}

NS_IMETHODIMP nsMsgMailNewsUrl::EqualsExceptRef(nsIURI* other, bool* result) {
  // The passed-in URI might be a mail news url. Pass our inner URL to its
  // Equals method. The other mail news url will then pass its inner URL to
  // to the Equals method of our inner URL. Other URIs will return false.
  if (other) return other->EqualsExceptRef(m_baseURL, result);

  return m_baseURL->EqualsExceptRef(other, result);
}

NS_IMETHODIMP
nsMsgMailNewsUrl::GetSpecIgnoringRef(nsACString& result) {
  return m_baseURL->GetSpecIgnoringRef(result);
}

NS_IMETHODIMP
nsMsgMailNewsUrl::GetDisplaySpec(nsACString& aUnicodeSpec) {
  return m_baseURL->GetDisplaySpec(aUnicodeSpec);
}

NS_IMETHODIMP
nsMsgMailNewsUrl::GetDisplayHostPort(nsACString& aHostPort) {
  return m_baseURL->GetDisplayHostPort(aHostPort);
}

NS_IMETHODIMP
nsMsgMailNewsUrl::GetDisplayHost(nsACString& aHost) {
  return m_baseURL->GetDisplayHost(aHost);
}

NS_IMETHODIMP
nsMsgMailNewsUrl::GetDisplayPrePath(nsACString& aPrePath) {
  return m_baseURL->GetDisplayPrePath(aPrePath);
}

NS_IMETHODIMP
nsMsgMailNewsUrl::GetHasRef(bool* result) {
  return m_baseURL->GetHasRef(result);
}

NS_IMETHODIMP nsMsgMailNewsUrl::SchemeIs(const char* aScheme, bool* _retval) {
  return m_baseURL->SchemeIs(aScheme, _retval);
}

nsresult nsMsgMailNewsUrl::Clone(nsIURI** _retval) {
  nsresult rv;
  nsAutoCString urlSpec;
  nsCOMPtr<nsIIOService> ioService = mozilla::components::IO::Service();
  NS_ENSURE_TRUE(ioService, NS_ERROR_UNEXPECTED);
  rv = GetSpec(urlSpec);
  NS_ENSURE_SUCCESS(rv, rv);
  nsCOMPtr<nsIURI> newUri;
  rv = ioService->NewURI(urlSpec, nullptr, nullptr, getter_AddRefs(newUri));
  NS_ENSURE_SUCCESS(rv, rv);

  // add the msg window to the cloned url
  nsCOMPtr<nsIMsgWindow> msgWindow(do_QueryReferent(m_msgWindowWeak));
  if (msgWindow) {
    nsCOMPtr<nsIMsgMailNewsUrl> msgMailNewsUrl = do_QueryInterface(newUri, &rv);
    NS_ENSURE_SUCCESS(rv, rv);
    msgMailNewsUrl->SetMsgWindow(msgWindow);
  }

  newUri.forget(_retval);
  return rv;
}

NS_IMETHODIMP nsMsgMailNewsUrl::Resolve(const nsACString& relativePath,
                                        nsACString& result) {
  // only resolve anchor urls....i.e. urls which start with '#' against the
  // mailnews url... everything else shouldn't be resolved against mailnews
  // urls.
  nsresult rv = NS_OK;

  if (relativePath.IsEmpty()) {
    // Return base URL.
    rv = GetSpec(result);
  } else if (!relativePath.IsEmpty() &&
             relativePath.First() == '#')  // an anchor
  {
    rv = m_baseURL->Resolve(relativePath, result);
  } else {
    // if relativePath is a complete url with it's own scheme then allow it...
    nsCOMPtr<nsIIOService> ioService = mozilla::components::IO::Service();
    NS_ENSURE_TRUE(ioService, NS_ERROR_UNEXPECTED);
    nsAutoCString scheme;

    rv = ioService->ExtractScheme(relativePath, scheme);
    // if we have a fully qualified scheme then pass the relative path back as
    // the result
    if (NS_SUCCEEDED(rv) && !scheme.IsEmpty()) {
      result = relativePath;
      rv = NS_OK;
    } else {
      result.Truncate();
      rv = NS_ERROR_FAILURE;
    }
  }

  return rv;
}

NS_IMETHODIMP nsMsgMailNewsUrl::GetDirectory(nsACString& aDirectory) {
  return m_baseURL->GetDirectory(aDirectory);
}

NS_IMETHODIMP nsMsgMailNewsUrl::GetFileName(nsACString& aFileName) {
  if (!mAttachmentFileName.IsEmpty()) {
    aFileName = mAttachmentFileName;
    return NS_OK;
  }
  return m_baseURL->GetFileName(aFileName);
}

NS_IMETHODIMP nsMsgMailNewsUrl::GetFileBaseName(nsACString& aFileBaseName) {
  return m_baseURL->GetFileBaseName(aFileBaseName);
}

NS_IMETHODIMP nsMsgMailNewsUrl::GetFileExtension(nsACString& aFileExtension) {
  if (!mAttachmentFileName.IsEmpty()) {
    int32_t pos = mAttachmentFileName.RFindChar(char16_t('.'));
    if (pos > 0)
      aFileExtension =
          Substring(mAttachmentFileName, pos + 1 /* skip the '.' */);
    return NS_OK;
  }
  return m_baseURL->GetFileExtension(aFileExtension);
}

nsresult nsMsgMailNewsUrl::SetFileNameInternal(const nsACString& aFileName) {
  mAttachmentFileName = aFileName;
  return NS_OK;
}

NS_IMETHODIMP nsMsgMailNewsUrl::GetQuery(nsACString& aQuery) {
  return m_baseURL->GetQuery(aQuery);
}

nsresult nsMsgMailNewsUrl::SetQuery(const nsACString& aQuery) {
  return NS_MutateURI(m_baseURL).SetQuery(aQuery).Finalize(m_baseURL);
}

nsresult nsMsgMailNewsUrl::SetQueryInternal(const nsACString& aQuery) {
  return NS_MutateURI(m_baseURL).SetQuery(aQuery).Finalize(m_baseURL);
}

nsresult nsMsgMailNewsUrl::SetQueryWithEncoding(
    const nsACString& aQuery, const mozilla::Encoding* aEncoding) {
  return NS_MutateURI(m_baseURL)
      .SetQueryWithEncoding(aQuery, aEncoding)
      .Finalize(m_baseURL);
}

NS_IMETHODIMP nsMsgMailNewsUrl::GetRef(nsACString& aRef) {
  return m_baseURL->GetRef(aRef);
}

nsresult nsMsgMailNewsUrl::SetRef(const nsACString& aRef) {
  return NS_MutateURI(m_baseURL).SetRef(aRef).Finalize(m_baseURL);
}

NS_IMETHODIMP nsMsgMailNewsUrl::GetFilePath(nsACString& o_DirFile) {
  return m_baseURL->GetFilePath(o_DirFile);
}

nsresult nsMsgMailNewsUrl::SetFilePath(const nsACString& i_DirFile) {
  return NS_MutateURI(m_baseURL).SetFilePath(i_DirFile).Finalize(m_baseURL);
}

NS_IMETHODIMP nsMsgMailNewsUrl::GetCommonBaseSpec(nsIURI* uri2,
                                                  nsACString& result) {
  return m_baseURL->GetCommonBaseSpec(uri2, result);
}

NS_IMETHODIMP nsMsgMailNewsUrl::GetRelativeSpec(nsIURI* uri2,
                                                nsACString& result) {
  return m_baseURL->GetRelativeSpec(uri2, result);
}

NS_IMETHODIMP nsMsgMailNewsUrl::SetMemCacheEntry(nsICacheEntry* memCacheEntry) {
  m_memCacheEntry = memCacheEntry;
  return NS_OK;
}

NS_IMETHODIMP nsMsgMailNewsUrl::GetMemCacheEntry(
    nsICacheEntry** memCacheEntry) {
  NS_ENSURE_ARG(memCacheEntry);
  nsresult rv = NS_OK;

  if (m_memCacheEntry) {
    NS_ADDREF(*memCacheEntry = m_memCacheEntry);
  } else {
    *memCacheEntry = nullptr;
    return NS_ERROR_NULL_POINTER;
  }

  return rv;
}

NS_IMETHODIMP nsMsgMailNewsUrl::GetMimeHeaders(nsIMimeHeaders** mimeHeaders) {
  NS_ENSURE_ARG_POINTER(mimeHeaders);
  NS_IF_ADDREF(*mimeHeaders = mMimeHeaders);
  return (mMimeHeaders) ? NS_OK : NS_ERROR_NULL_POINTER;
}

NS_IMETHODIMP nsMsgMailNewsUrl::SetMimeHeaders(nsIMimeHeaders* mimeHeaders) {
  mMimeHeaders = mimeHeaders;
  return NS_OK;
}

NS_IMETHODIMP nsMsgMailNewsUrl::LoadURI(nsIDocShell* docShell,
                                        uint32_t aLoadFlags) {
  NS_ENSURE_ARG_POINTER(docShell);
  RefPtr<nsDocShellLoadState> loadState = new nsDocShellLoadState(this);
  loadState->SetLoadFlags(aLoadFlags);
  loadState->SetLoadType(MAKE_LOAD_TYPE(LOAD_NORMAL, aLoadFlags));
  loadState->SetFirstParty(false);
  loadState->SetTriggeringPrincipal(nsContentUtils::GetSystemPrincipal());
  return docShell->LoadURI(loadState, false);
}

#define SAVE_BUF_SIZE FILE_IO_BUFFER_SIZE
class nsMsgSaveAsListener : public nsIStreamListener {
 public:
  NS_DECL_ISUPPORTS
  NS_DECL_NSIREQUESTOBSERVER
  NS_DECL_NSISTREAMLISTENER

  nsMsgSaveAsListener(nsIFile* aFile, bool addDummyEnvelope);
  nsresult SetupMsgWriteStream(nsIFile* aFile, bool addDummyEnvelope);

 protected:
  virtual ~nsMsgSaveAsListener();
  nsCOMPtr<nsIOutputStream> m_outputStream;
  nsCOMPtr<nsIFile> m_outputFile;
  bool m_addDummyEnvelope;
  bool m_writtenData;
  uint32_t m_leftOver;
  char m_dataBuffer[SAVE_BUF_SIZE +
                    1];  // temporary buffer for this save operation
};

NS_IMPL_ISUPPORTS(nsMsgSaveAsListener, nsIStreamListener, nsIRequestObserver)

nsMsgSaveAsListener::nsMsgSaveAsListener(nsIFile* aFile,
                                         bool addDummyEnvelope) {
  m_outputFile = aFile;
  m_writtenData = false;
  m_addDummyEnvelope = addDummyEnvelope;
  m_leftOver = 0;
}

nsMsgSaveAsListener::~nsMsgSaveAsListener() {}

NS_IMETHODIMP nsMsgSaveAsListener::OnStartRequest(nsIRequest* request) {
  return NS_OK;
}

NS_IMETHODIMP
nsMsgSaveAsListener::OnStopRequest(nsIRequest* request, nsresult aStatus) {
  if (m_outputStream) {
    m_outputStream->Flush();
    m_outputStream->Close();
  }
  return NS_OK;
}

NS_IMETHODIMP nsMsgSaveAsListener::OnDataAvailable(nsIRequest* request,
                                                   nsIInputStream* inStream,
                                                   uint64_t srcOffset,
                                                   uint32_t count) {
  nsresult rv;
  uint64_t available;
  rv = inStream->Available(&available);
  if (!m_writtenData) {
    m_writtenData = true;
    rv = SetupMsgWriteStream(m_outputFile, m_addDummyEnvelope);
    NS_ENSURE_SUCCESS(rv, rv);
  }

  bool useCanonicalEnding = false;
  // We know the request is an nsIChannel we can get a URI from, but this is
  // probably bad form. See Bug 1528662.
  nsCOMPtr<nsIChannel> channel = do_QueryInterface(request, &rv);
  NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
                       "error QI nsIRequest to nsIChannel failed");
  NS_ENSURE_SUCCESS(rv, rv);
  nsCOMPtr<nsIURI> uri;
  rv = channel->GetURI(getter_AddRefs(uri));
  NS_ENSURE_SUCCESS(rv, rv);
  nsCOMPtr<nsIMsgMessageUrl> msgUrl = do_QueryInterface(uri);
  if (msgUrl) msgUrl->GetCanonicalLineEnding(&useCanonicalEnding);

  const char* lineEnding = (useCanonicalEnding) ? CRLF : MSG_LINEBREAK;
  uint32_t lineEndingLength = (useCanonicalEnding) ? 2 : MSG_LINEBREAK_LEN;

  uint32_t readCount, maxReadCount = SAVE_BUF_SIZE - m_leftOver;
  uint32_t writeCount;
  char *start, *end, lastCharInPrevBuf = '\0';
  uint32_t linebreak_len = 0;

  while (count > 0) {
    if (count < maxReadCount) maxReadCount = count;
    rv = inStream->Read(m_dataBuffer + m_leftOver, maxReadCount, &readCount);
    if (NS_FAILED(rv)) return rv;

    m_leftOver += readCount;
    m_dataBuffer[m_leftOver] = '\0';

    start = m_dataBuffer;
    // make sure we don't insert another LF, accidentally, by ignoring
    // second half of CRLF spanning blocks.
    if (lastCharInPrevBuf == '\r' && *start == '\n') start++;

    end = PL_strpbrk(start, "\r\n");
    if (end) linebreak_len = (end[0] == '\r' && end[1] == '\n') ? 2 : 1;

    count -= readCount;
    maxReadCount = SAVE_BUF_SIZE - m_leftOver;

    if (!end && count > maxReadCount)
      // must be a very very long line; sorry cannot handle it
      return NS_ERROR_FAILURE;

    while (start && end) {
      if (m_outputStream && PL_strncasecmp(start, "X-Mozilla-Status:", 17) &&
          PL_strncasecmp(start, "X-Mozilla-Status2:", 18) &&
          PL_strncmp(start, "From - ", 7)) {
        rv = m_outputStream->Write(start, end - start, &writeCount);
        nsresult tmp =
            m_outputStream->Write(lineEnding, lineEndingLength, &writeCount);
        if (NS_FAILED(tmp)) {
          rv = tmp;
        }
      }
      start = end + linebreak_len;
      if (start >= m_dataBuffer + m_leftOver) {
        maxReadCount = SAVE_BUF_SIZE;
        m_leftOver = 0;
        break;
      }
      end = PL_strpbrk(start, "\r\n");
      if (end) linebreak_len = (end[0] == '\r' && end[1] == '\n') ? 2 : 1;
      if (start && !end) {
        m_leftOver -= (start - m_dataBuffer);
        memcpy(m_dataBuffer, start,
               m_leftOver + 1);  // including null
        maxReadCount = SAVE_BUF_SIZE - m_leftOver;
      }
    }
    if (NS_FAILED(rv)) return rv;
    if (end) lastCharInPrevBuf = *end;
  }
  return rv;

  //  rv = m_outputStream->WriteFrom(inStream, std::min(available, count),
  //  &bytesWritten);
}

nsresult nsMsgSaveAsListener::SetupMsgWriteStream(nsIFile* aFile,
                                                  bool addDummyEnvelope) {
  // If the file already exists, delete it, but do this before
  // getting the outputstream.
  // Due to bug 328027, the nsSaveMsgListener created in
  // nsMessenger::SaveAs now opens the stream on the nsIFile
  // object, thus creating an empty file. Actual save operations for
  // IMAP and NNTP use this nsMsgSaveAsListener here, though, so we
  // have to close the stream before deleting the file, else data
  // would still be written happily into a now non-existing file.
  // (Windows doesn't care, btw, just unixoids do...)
  aFile->Remove(false);

  nsresult rv = MsgNewBufferedFileOutputStream(getter_AddRefs(m_outputStream),
                                               aFile, -1, 0666);
  NS_ENSURE_SUCCESS(rv, rv);

  if (m_outputStream && addDummyEnvelope) {
    nsAutoCString result;
    uint32_t writeCount;

    time_t now = time((time_t*)0);
    char* ct = ctime(&now);
    // Remove the ending new-line character.
    ct[24] = '\0';
    result = "From - ";
    result += ct;
    result += MSG_LINEBREAK;
    m_outputStream->Write(result.get(), result.Length(), &writeCount);

    result = "X-Mozilla-Status: 0001";
    result += MSG_LINEBREAK;
    result += "X-Mozilla-Status2: 00000000";
    result += MSG_LINEBREAK;
    m_outputStream->Write(result.get(), result.Length(), &writeCount);
  }

  return rv;
}

NS_IMETHODIMP nsMsgMailNewsUrl::GetSaveAsListener(
    bool addDummyEnvelope, nsIFile* aFile, nsIStreamListener** aSaveListener) {
  NS_ENSURE_ARG_POINTER(aSaveListener);
  nsMsgSaveAsListener* saveAsListener =
      new nsMsgSaveAsListener(aFile, addDummyEnvelope);
  return saveAsListener->QueryInterface(NS_GET_IID(nsIStreamListener),
                                        (void**)aSaveListener);
}

NS_IMETHODIMP
nsMsgMailNewsUrl::SetFailedSecInfo(nsITransportSecurityInfo* secInfo) {
  mFailedSecInfo = secInfo;
  return NS_OK;
}

NS_IMETHODIMP nsMsgMailNewsUrl::GetFailedSecInfo(
    nsITransportSecurityInfo** secInfo) {
  NS_ENSURE_ARG_POINTER(secInfo);
  NS_IF_ADDREF(*secInfo = mFailedSecInfo);
  return NS_OK;
}

NS_IMETHODIMP nsMsgMailNewsUrl::SetFolder(nsIMsgFolder* /* aFolder */) {
  return NS_ERROR_NOT_IMPLEMENTED;
}

NS_IMETHODIMP nsMsgMailNewsUrl::GetFolder(nsIMsgFolder** /* aFolder */) {
  return NS_ERROR_NOT_IMPLEMENTED;
}

NS_IMETHODIMP nsMsgMailNewsUrl::GetIsMessageUri(bool* aIsMessageUri) {
  NS_ENSURE_ARG(aIsMessageUri);
  nsAutoCString scheme;
  m_baseURL->GetScheme(scheme);
  *aIsMessageUri = StringEndsWith(scheme, "-message"_ns);
  return NS_OK;
}

NS_IMPL_ISUPPORTS(nsMsgMailNewsUrl::Mutator, nsIURISetters, nsIURIMutator)

NS_IMETHODIMP
nsMsgMailNewsUrl::Mutate(nsIURIMutator** aMutator) {
  RefPtr<nsMsgMailNewsUrl::Mutator> mutator = new nsMsgMailNewsUrl::Mutator();
  nsresult rv = mutator->InitFromURI(this);
  if (NS_FAILED(rv)) {
    return rv;
  }
  mutator.forget(aMutator);
  return NS_OK;
}